Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Use of Const keyword in ANSI C Message-ID: <366@quintus.UUCP> Date: 8 Sep 88 09:45:34 GMT References: <441@optilink.UUCP> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 16 In article <441@optilink.UUCP> cramer@optilink.UUCP (Clayton Cramer) writes: >I'm starting to use the 'const' keyword with the Microsoft V5.1 C compiler. >I've found something that may be a bug, or it may be that I don't >adequately understand 'const'. >I've defined a structure: > typedef struct Tag { ... const char* C; } TestType; > TestType Test1 = ...; > Test1.C = "not a test case"; /* compiler accepts this -- bad */ The compiler is right: const char *C is to be read *backwards*: C is a pointer to readonly characters. If you want C to be constant, say char * const C; /* C is a constant pointer to char */ If you want *both* C and what it points to to be readonly, say const char * const C; The "cdecl" utility -- available from comp.sources archives -- is a big help!