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]

Re: aliasing warnings [patch]


> To: rth@cygnus.com
> From: Mark Mitchell <mark@codesourcery.com>
> Date: Thu, 16 Sep 1999 14:27:29 -0700

>     >> char c[4]; *((int *) &c[0]) = 3;

>     Richard> Modulo the alignment argument, isn't this really ok?

Yes (provided sizeof(int) <= 4 and c is suitably aligned.

> I don't think this is conforming ISO C.  The dynamic type of the
> object is `char ()[4]', while the lvalue is of type `int'.

Nope.  Try again:

  A program may end the lifetime of any object by reusing the storage
  which the object occupies

and

1 The  lifetime of an object is a runtime property of the  object.   The
  lifetime of an object of type  T begins when:

  - storage with the proper alignment and size for type  T is  obtained,

  The lifetime of an object of type  T ends when:

  - if  T is a class type with  a  non-trivial  destructor  (12.4),  the
    destructor call starts, or

  - the storage which the object occupies is reused or released.

are pretty clear.  They were meant to put into words our understanding
of the ISO C memory model.  You're thinking of:

15If a program attempts to access the stored value of an object  through
  an  lvalue  of  other  than one of the following types the behavior is
  undefined46):

  - the dynamic type of the object,

but this does not prohibit the above.

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