Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!umix!metavax!marc From: marc@metavax.UUCP (Marc Paige) Newsgroups: comp.lang.c Subject: Re: Use of Const keyword in ANSI C Message-ID: <3612@metavax.UUCP> Date: 14 Sep 88 13:19:18 GMT References: <441@optilink.UUCP> <8454@smoke.ARPA> Reply-To: marc@metavax.UUCP (Marc Paige) Organization: Meta Systems, Ltd. -- Ann Arbor, MI Lines: 27 In article <8454@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <441@optilink.UUCP> cramer@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