[comp.lang.c] const applied to typedef'd pointer + const functions

maart@cs.vu.nl (Maarten Litmaath) (03/03/89)

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'. ADO's example `const string const x' should translate to
`const char * const x'. I guess the problem is the equivalence of `const char'
and `char const', which - generalized - leads to `const string' ==
`string const'. This equivalence is dubious, or?

BTW, how about letting `const double sin(double)' mean
"sin() is a `true' function"? (`true': same args -> same result [i.e. no
side-effects])
-- 
 "Those who do not understand Henry     |Maarten Litmaath @ VU Amsterdam:
Spencer are condemned to reinvent DOS." |maart@cs.vu.nl, mcvax!botter!maart

karl@haddock.ima.isc.com (Karl Heuer) (03/04/89)

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