Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: const applied to typedef'd pointer + const functions Message-ID: <11946@haddock.ima.isc.com> Date: 3 Mar 89 21:27:39 GMT References: <9078@elsie.UUCP> <9709@smoke.BRL.MIL> <2105@solo11.cs.vu.nl> <11917@haddock.ima.isc.com> <2117@solo11.cs.vu.nl> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 31 In article <2117@solo11.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >karl@haddock.ima.isc.com (Karl Heuer) writes: >>After `typedef char *string', >>`string const x' means `char * const x' rather than `char const * x'. > >Of course. But I was talking of `const string x'; in my opinion this should >mean `const char *x'. Having (const int)==(int const) but (const string)!=(string const) would somewhat defeat the purpose of typedefs as an abstraction mechanism. The user shouldn't have to know that "string" is a pointer type. Actually, I think that allowing a type qualifier before the type name is as dubious as allowing the storage class to be after it (which is now obsolescent). In my view, `static int const x' is the correct way to write that declaration. Writing `const' before `int' is misleading; it suggests that `const' behaves like a storage class. (This entire paragraph is the opinion of the author and is not intended to spark a new programming-style war. I will probably not bother to respond if such a war erupts anyway.) >BTW, how about letting `const double sin(double)' mean [sin() is pure]? I already noted this possibility in <11819@haddock.ima.isc.com>. I have since been informed that the latest version of gcc does in fact use `const' to mark pure functions, and `volatile' to mark nonreturning functions. As I said in the aforementioned article, though: |It remains unclear whether this would be any less of a mistake than the |overloading of `static' and `break'. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint