const semantics

David Tanguay datangua at watmath.waterloo.edu
Sat Jun 29 09:26:30 AEST 1991


In article <785 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>I agree.  There are really two orthogonal concepts smooshed (that's a
>technical term) together into the 'const' keyword.  One is concept is
>"unchanging", the other is "read-only".

I don't think "const" means "unchanging" in ANSI C. You can't change the
value through the const qualified handle, but there's nothing wrong with
changing it through an alias (or hardware magic). I.e.,

	int i = 5;
	const int *pi = &i;
    a:
	i = 6;              /* this is okay by ANSI */
    b:

At "a:" *pi is 5, and at "b:" it is 6, in conforming code.

>	extern const int i = 10;
>This looks like an error, as it would be in ANSI C, where you cannot
>initialize an 'extern' variable.

I think this is correct inside a block scope (i.e. somewhere in a function),
but the initialization is okay outside of functions.
-- 
David Tanguay                  datanguay at watmath.waterloo.edu
Thinkage, Ltd.                 dat at Thinkage.On.CA



More information about the Comp.lang.c mailing list