Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Use of Const keyword in ANSI C Message-ID: <13447@mimsy.UUCP> Date: 8 Sep 88 18:59:58 GMT References: <441@optilink.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 23 In article <441@optilink.UUCP> cramer@optilink.UUCP (Clayton Cramer) writes: [structure containing] > const char* C; > > Test1.C = "not a test case"; /* compiler accepts this -- bad */ > >Should the attempt to set Test1.C to point to another string cause a >complaint from the compiler? ... [or] have I missed something here in >my understanding of 'const' ... ? The latter: `const' applies here to the characters, not to the pointer. So `Test1.C[n] = expr' is illegal, but `Test1.C = expr' is legal. If you just want the pointer to be constant, use char *const C; and if you want both constant, use const char *const C; The `volatile' modifier works in the same fashion. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris