Re: OON: generalizing restrict

From: Bill Homer (homer@sgi.com)
Date: Sun Apr 09 2000 - 12:16:49 EST


On Tue, 4 Apr 2000 jsiek@lsc.nd.edu wrote:

> Bill Homer writes:
> > In fact, the semantics of copy would not allow it to be declared
> > with unaliased iterators, because some aliasing is allowed:
>
> I'm sorry, I should have been more clear about what I was talking
> about. I was trying to talk about a hypothetical version of copy()
> that doesn't allow aliasing. To clarify, let's call this
> restricted_copy(). Now suppose that restricted_copy() calls memcpy()
> in one of its specializations. So the problem is, how can I ensure
> that restricted_copy() only gets called with "restricted" iterators so
> that I don't get a compiler error at the point where memcpy() is
> called?

Because qualifiers at the top level on the type of a function
parameter are ignored for the purpose of determining the type of the
function, you cannot get an error message from a conforming compiler
about calling memcpy with an unqualified argument.

The presence of restrict in the prototype for memcpy in the library
header serves only to give the programmer notice that the function is
implemented with the assumption that dereferencing its parameters as
required for the copy will not result in any aliasing. The type
system does not provide any means to guarantee the truth of this
assumption for a particular call.

On the other hand, if the definition of memcpy is written in C, then
the presence of restrict in the prototype that is part of that
definition can allow the compiler to optimize the body of the function
more aggressively. But notice that the qualifier could be present in
the definition and absent in the declaration in the header, and they
would still be compatible.

So I believe that there would be no syntactic problem with calling
restricted_copy in whatever context it is semantically appropriate,
regardless of the qualification of the arguments.

Nevertheless, I think we agree that the real problem is devising some
congenial syntactic means of specifying restricted_copy as a
specialization of the generic copy. If a restrict qualifier at the
top level in a type follows the same rules as const and volatile
(which I think it should), then it does not provide such a means.
I want return to this in another message.

Let me know if I have still not understood your point.

-- 
Bill Homer
(651) 683-5606   Cray Inc.
homer@cray.com   655F Lone Oak Drive, Eagan, MN 55121

--------------------- Object Oriented Numerics List -------------------------- * To subscribe/unsubscribe: use the handy web form at http://oonumerics.org/oon/ * If this doesn't work, please send a note to owner-oon-list@oonumerics.org



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:12 EST