Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Question on const applied to typedef'd pointer Message-ID: <9748@smoke.BRL.MIL> Date: 28 Feb 89 04:59:07 GMT References: <9078@elsie.UUCP> <9709@smoke.BRL.MIL> <9081@elsie.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <9081@elsie.UUCP> ado@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.