Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!ncar!tank!mimsy!eneevax!cvl!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: comp.lang.c Subject: Re: Question on const applied to typedef'd pointer Message-ID: <9083@elsie.UUCP> Date: 28 Feb 89 02:54:03 GMT References: <9078@elsie.UUCP> <9709@smoke.BRL.MIL> Organization: NIH-LEC, Bethesda, MD Lines: 24 > > 1> const char * const foo; > > typedef char * bar; > > 2> const bar const baz; > > . . .should line 1 above have the same meaning as line 2 above. . . > No; you can't slip a qualifier "inside" an existing typedef. Thanks for the reply; now it's time for Double Jeopardy: Suppose you're working with software such as MIT's X Window System, which has declarations such as typedef char *String; and typedef Widget *WidgetList; in its header files. Suppose also you have a function argument of type String that refers to an object you're not supposed to change, and that you want to ensure isn't itself changed in the body of the function. Now if the argument was a plain "char *", you could use void function(const char * const argument) { /* whatever */ } to achieve the desired effect. But what of "String"? Using void function(const String const argument) { /* whatever */ } won't work, as explained in the reply. Is there some other way to do the job? -- Arthur David Olson ado@ncifcrf.gov ADO is a trademark of Ampex.