This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
- To: mark AT codesourcery dot com, rth AT cygnus dot com
- Subject: Re: aliasing warnings [patch]
- From: Mike Stump <mrs AT wrs dot com>
- Date: Thu, 16 Sep 1999 15:05:39 -0700 (PDT)
- Cc: egcs-patches AT egcs.cygnus dot com, egcs AT egcs.cygnus dot com, jason AT cygnus dot com, zack AT bitmover dot com
> 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.