Question on const applied to typedef'd pointer

Arthur David Olson ado at elsie.UUCP
Tue Feb 28 12:54:03 AEST 1989


> > 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 at ncifcrf.gov    ADO is a trademark of Ampex.



More information about the Comp.lang.c mailing list