Question on const applied to typedef'd pointer
Doug Gwyn
gwyn at smoke.BRL.MIL
Tue Feb 28 14:59:07 AEST 1989
In article <9081 at elsie.UUCP> ado at elsie.UUCP (Arthur David Olson) writes:
>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?
Sure; use the first form (involving char *). Despite appearances,
typedef does not create a new type. Of course, you could define a
CString typedef that is just like a String except that the bytes
pointed at are considered read-only, then use the CString typedef
as shorthand in your example.
I appreciate why you'd like to do things the way you suggest, but
if you think hard enough about it you'll realize that it cannot be
made to work in full generality -- there can be many levels within
a type at which "const" could be applied, but the typedef name has
only two adjacent sides as possible slots for sticking in "const",
not enough for all the possible levels.
More information about the Comp.lang.c
mailing list