Use of Const keyword in ANSI C

Doug Gwyn gwyn at smoke.ARPA
Thu Sep 8 15:23:09 AEST 1988


In article <441 at optilink.UUCP> cramer at optilink.UUCP (Clayton Cramer) writes:
>    typedef struct Tag
>        {
>        const char*     C;
>        } TestType;
>    Test1.C = "not a test case";    /* compiler accepts this -- bad */

That's okay.  You've declared the C member to point to const chars,
and set it to point to a string literal.  If you want the POINTER to
be const, instead of what it points to, try
	char const *	C;

"const" is a type qualifer, not a storage class, so its relative
position within the type specifiers matters.



More information about the Comp.lang.c mailing list