Use of Const keyword in ANSI C
Marc Paige
marc at metavax.UUCP
Wed Sep 14 23:19:18 AEST 1988
In article <8454 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>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.
The second declaration is also wrong!! char const and const char are
equivilent. The way to declare a const pointer is:
char * const C;
This declares member C to be a const pointer to char. You are correct in
your last statement though, const is a qualifier.
------------------------------------------------------------------------
"tired and shagged out from a prolonged squawk" - mpfc the parrot sketch
More information about the Comp.lang.c
mailing list