Newsgroups: comp.lang.c
Path: utzoo!utgpu!watserv1!watmath!datangua
From: datangua@watmath.waterloo.edu (David Tanguay)
Subject: Re: const semantics
Message-ID: <1991Jun28.232630.14277@watmath.waterloo.edu>
Organization: University of Waterloo
References: <1991Jun26.232121.29755@watmath.waterloo.edu> <14737@dog.ee.lbl.gov> <785@taumet.com>
Date: Fri, 28 Jun 1991 23:26:30 GMT
Lines: 26

In article <785@taumet.com> steve@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@watmath.waterloo.edu
Thinkage, Ltd.                 dat@Thinkage.On.CA
