Can ANSI Standard C be "Optimized"

John Gilmore gnu at sun.uucp
Tue Mar 20 04:38:16 AEST 1984


Rather than add the "volatile" attribute to variable declarations, the C
standards committee has taken a safer alternative:  Assume that everything
is volatile, but permit it to be declared "const".  An object declared
"const" cannot be modified.  Furthermore, the "const" attribute can appear
at each level of indirection; eg

	const char *pcc;

declares a (modifiable) pointer, which is guaranteed by the programmer
to point to non-modifiable storage (a const char).  If you say

	char *const pcc = "string";

then it can (for example) put the string in the text segment.  A declaration
like

	char *const cpc;

declares a pointer, cp, which is not modifiable; but the object it points
to (a char) can be modified.

This can be used by the compiler -- there's no need to worry about aliasing
of const things.  For example, if a compiler already has the value of cpc in
a register due to a previous calculation, it need not reload it.  This can
be valuable for function parameters -- mostly they are constant throughout
the function.

The draft standard goes into more detail.  If you don't know anyone who has
one (or is on the committee), call CBEMA at 202-737-8888; they should be
able to point you right.  (Don't ask me.)



More information about the Comp.lang.c mailing list