This is the mail archive of the gcc@gcc.gnu.org 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: GCC aliasing rules: more aggressive than C99?


On Tue, 5 Jan 2010, Vincent Lefevre wrote:

> On 2010-01-05 15:30:11 +0000, Joseph S. Myers wrote:
> > On Tue, 5 Jan 2010, Vincent Lefevre wrote:
> > 
> > > On 2010-01-05 10:31:13 +0000, Andrew Haley wrote:
> > > > "An object shall have its stored value accessed only by an lvalue
> > > > expression that has one of the following types:
> > > > 
> > > > but
> > > > 
> > > >  (union u*)&i
> > > > 
> > > > is not a legal lvalue expression because the dereference is undefined
> > > > behaviour.  You may only dereference a pointer as permitted by 6.3.2.3.
>                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > For the same reason, (char *) &i could not be dereferenced, and this
> > > would break a lot of code!
> > 
> > No, read 6.3.2.3 again.  Specifically, where it says "When a pointer to an 
> > object is converted to a pointer to a character type, the result points to 
> > the lowest addressed byte of the object. Successive increments of the 
> > result, up to the size of the object, yield pointers to the remaining 
> > bytes of the object.".
> 
> 6.3.2.3 says that one can *convert* the pointer, but not that one can
> *dereference* it.

You can dereference it if it is defined where (to what object of the 
relevant type) it points, and no other rule prohibits the dereference.

-- 
Joseph S. Myers
joseph@codesourcery.com


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