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: C ABI: struct/union inconsistency




--On Friday, September 27, 2002 10:06:16 AM -0700 Richard Henderson <rth@redhat.com> wrote:

On Wed, Sep 25, 2002 at 04:58:11PM -0700, Mark Mitchell wrote:
I also do not know if some piece of code in the Linux
kernel is going to depend on the current behavior; we might want to
have a switch for the old behavior.
I think that we should leave structures with no members whatsoever
alone.  I think that as shown by the linux kernel code, this is a
useful feature.
We should at least document this behavior.  It is, I believe, different
from what any other compiler does.

I must say that I'm concerned about the fact that things like:

 struct S s[3];

 ... sizeof (s) / sizeof (S) ...

won't work, and that s[0] and s[1] have the same address.

At least in C++, that's a major violation of the object model; the
standard basically defines object identity as the pair of the object's
type and the object's address.  (I don't know if the C standard really
defines this concept.)

Finally, the C++ ABI requires that PODs have the same layout as the
equivalent C structures, but, on the other hand, the C++ standard
requires that empty structures have size one.

That means we lose C/C++ compatibility even for a type which is in
the common subset of both languages.

Perhaps we should offer a switch and/or attribute to control this
behavior?

I don't care what we do with structures with no named members, but
some unnamed members.  As Joseph points out, this is undefined in C.
We might as well match whatever the C++ language requires, simply
for consistency.
That sounds, then, like an agreement to change the alignment of the
union example to match the struct example?

--
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com


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