This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] COMPONENT_REFs referring to non-aliasing structuresdon't alias - take 2
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Geoff Keating <geoffk at redhat dot com>
- Cc: <dann at godzilla dot ICS dot UCI dot EDU>, <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 12 Mar 2002 00:10:14 +0000 (GMT)
- Subject: Re: [patch] COMPONENT_REFs referring to non-aliasing structuresdon't alias - take 2
On Mon, 11 Mar 2002, Geoff Keating wrote:
> One question that I'm not clear on:
>
> Is this program
>
> int main(void)
> {
> struct s1 {
> short a[2];
> int b;
> };
> struct s2 {
> int a;
> int b;
> } t;
>
> if (offsetof (struct s1, b) == offsetof (struct s2, b))
> {
> t.b = 2;
> if ( ((struct s2 *)&t)->b != 2)
> abort ();
> }
> return 0;
> }
>
> strictly conforming? Normally, type punning like this is not allowed,
It isn't s.c. for the trivial reason that the two structures might have
different alignment requirements. Given that they have the same alignment
requirements, I don't see anything undefined in it.
> but here we have two things at the same address ("(char *)&t +
> offsetof (struct s1, b)") with the same type ("int")... It depends on
> the definition of "object" in the C standard, I fear.
That's why I'm referring to Nick Maclaren's paper - the problem, in
general, is what the object is, an int or a struct or a component byte, or
an array and if so what size of array, .... (These problems also have
important applications for the use of the C standard as an underlying
standard for standards such as POSIX threads or for multiprocessing, where
you need to know how large the objects being accessed in parallel are.)
I would again urge anyone interested in such technical details of the C
standard to join their National Body's C panel.
--
Joseph S. Myers
jsm28@cam.ac.uk