This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why are we not using const?

On 6/29/06, Dave Korn <> wrote:
On 29 June 2006 14:55, Andrew Pinski wrote:

> On Jun 29, 2006, at 9:51 AM, Dave Korn wrote:
>>    That's cheating!  You casted away const, it's a blatant aliasing
>> violation, you deserve everything you get.
> No it is not, in fact it is legal C and there is no aliasing
> violation as you
> are still accessing the memory as an "int".

  Sorry, 'aliasing' was the wrong choice of word.  But it's really legal to
cast away const?  I'm boggled.  In that case it simply might as well not exist
at all; it conveys no usable semantic information.  I would argue that const
should be removed from the language if this is the case; if all you want is to
document the properties of function args, it makes more sense to do it with
macros that #define to nothing, like M$ does with 'IN', 'OUT', 'OPTIONAL' and
so on in all their header files.


It's useful for qualifiers on the actual object like

const int foo = 1;

only for pointer targets it's useless but "needed" to form &foo, which
is const int*.  And it is undefined if you try to modify foo via

int * bar = (int*)&foo;
*bar = 1;

so, it's only the CV qualifier of the object that matters, not the one
you stick to some arbitrary pointer to an object.

The solution is of course to teach the middle-end a new concept
of pointer to non-modifiable memory and do some language extension
to use it.  Maybe there even are languages that have a useful const
concept (like C++ for the this object on const methods).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]