Teaching const: decoding declarations

Chris Torek chris at mimsy.UUCP
Sun Apr 10 03:22:25 AEST 1988


-In article <27071 at amdahl.uts.amdahl.com> nw at amdahl.uts.amdahl.com
-(Neal Weidenhofer) writes:
->	int * const a;
->decodes as:
->	a is a constant,
->	a is a constant pointer,
->	a is a constant pointer to an int.
->		(i.e., a cannot be modified but *a can.)

In article <9683 at ism780c.UUCP> news at ism780c.UUCP (News system) writes:
-Note that:
-	 int a[1];
-decodes as:
-       a is a constant,

Nope.

-       a is a constant pointer,
-       a is a constant pointer to an int.
-	       (i.e., a cannot be modified but *a can.)
-
-But there must (?) be some difference between the two.  How do you teach
-this?

Start with the right expansion:

	a is an array
		      1
			of int
		(i.e., `a' used in rvalue contexts is an object of
		type pointer to int, but a cannot be modified because
		it is an array).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list