const applied to typedef'd pointer + const functions

Karl Heuer karl at haddock.ima.isc.com
Sat Mar 4 07:27:39 AEST 1989


In article <2117 at solo11.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>karl at 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 at 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 at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list