This is the mail archive of the
mailing list for the GCC project.
RE: why are we not using const?
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Kaveh R. Ghazi'" <ghazi at caipclassic dot rutgers dot edu>, <pinskia at physics dot uc dot edu>
- Cc: <gcc at gnu dot org>, <gdr at integrable-solutions dot net>, <lopezibanez at gmail dot com>, <richard dot guenther at gmail dot com>
- Date: Thu, 29 Jun 2006 16:18:10 +0100
- Subject: RE: why are we not using const?
On 29 June 2006 16:15, Kaveh R. Ghazi 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".
> > -- Pinski
> "Legal" does not mean it's a good idea. Bypassing const through casts
> is like ignoring documentation. You get what you deserve.
> E.g. if the object referred to by the pointer is in a read-only
> section, casting away const-ness and modifying it leads to a core
I believe that's basically what Andreas was pointing out; in that case, you
*are* violating the type of the underlying object.
Can't think of a witty .sigline today....