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 01:43:48 PM -0700 Richard Henderson <rth@redhat.com> wrote:

On Fri, Sep 27, 2002 at 11:52:46AM -0700, Mark Mitchell wrote:
My point was that I would like a header file that looks like:

extern "C" {
 struct S {};
 ...
}

to have the same meaning in both languages; that's not possible if S has
size zero in C.
It's also not possible if one writes

  extern "C" {
    struct S {
      const int i;
    };
  }

as they have different meanings in C and C++.  So I don't see that your
point necessarily holds.  The fact of the matter is that the two languages
do not line up 100%, and one has to live with it.
That's true -- there are a few other places in the common subset that
don't line up in terms of semantics.

As far as I know, however, this empty struct issue is the only one that
has an effect on layout, which is clearly a very important issue.  Most
of the other issues result in errors in one language or the other.

If emtpy structures were rejected in C mode, I'd be much less nervous; at
least the errors would be easily detected.

Why not ask the kernel developers about something like:

 struct S __attribute__((possibly_empty)) {};

?

The idea being that if S has no members, the size ends up zero.

We could support this attribute in C++ as well, and then have
compatibility between C and C++.

--
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]