Does extern "const" allocate storage?

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Mar 20 12:49:03 AEST 1988


In article <7712 at apple.Apple.Com> lenoil at apple.UUCP (Robert Lenoil) writes:
>const int foo = 3;

In general, "const" in ANSI C does not mean the same as in Pascal etc.
(C's equivalent to that is "manifest constant" preprocessor macros.)
Unless the compiler can ascertain that it is impossible for any code
to need the variable `foo' to really exist, it is obliged to generate
storage for `foo'.  Think of "const" as "readonly" and you'll have a
good idea of its intended properties.

>... can someone translate their definition of noalias into English for me?

There are definitely some problems with the current specification of
type qualifiers, which will probably be fixed one way or another at
the April X3J11 meeting.  (The possibilities range from minor tweaks
to the current specs to fix technical errors, through removing
"noalias" altogether and possibly adding some other support for
certain types of optimization, such as Peter Darnell's [] proposal.)

Basically, "noalias" is a hint that, although as usual in C there
can be multiple "handles", i.e. access paths to an object's content,
the first noalias "handle" used is the master version, which is
guaranteed to always reference the official object content, and access
via other handles need not always go fetch the current object content
for safety (as is required if "noalias" is not used), but instead can
use cached copies of the object.  The only purpose of all this is to
allow just that sort of caching, which is a form of optimization that
some people consider important.  For example, it allows vectorizing
machines to employ vector operations where normally C would say that
they could not be safely used.

I think I got that substantially right, although I may have messed
up a few details.  Hey, I don't plan to use this stuff!



More information about the Comp.lang.c mailing list