OON: const + restrict

From: Bill Homer (homer@sgi.com)
Date: Fri Mar 24 2000 - 19:00:51 EST


Arch D. Robison wrote:

> As a writer of an optimizing compiler, I have to ignore "const",
> except for global variables declared as const that have static initializers.
> It's useless otherwise.

Note that the restrict qualifier can be used to strengthen
the meaning of const (in a conforming program, as always).
For example:

  int f(const int * restrict p) {
    ... /* The value of *p shall not be modified, so the */
    return *p; /* return value can be loaded at any point in f. */
   }

The assertion in the comment depends only on the declared type of p
and not on what is in the body of f().

The rationale is that, on entry to the function, p provides the only
(conforming) means to access the int to which it points, so it makes
sense to mandate the same (strong) semantics for the const qualifier
that you would have in a definition of a variable of type int.

Bill Homer
(651) 683-5606 Silicon Graphics, 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:11 EST