Document empty structures

Richard Earnshaw rearnsha@arm.com
Mon Apr 14 17:59:00 GMT 2003


> 
> On Monday, April 14, 2003, at 08:06  AM, Richard Earnshaw wrote:
> 
> >> On Fri, 11 Apr 2003, Geoffrey Keating wrote:
> >>
> >>> This adds documentation of GCC's empty structure extension.
> >>
> >> I think there needs to be something about how empty structures 
> >> interact
> >> with initializer lists (when initializing a structure which has as an
> >> element an empty structure): do lists of scalars ignore the empty
> >> structure, does { } explicitly initialize it, ...?
> >>
> >> -- 
> >> Joseph S. Myers
> >> jsm28@cam.ac.uk
> >
> > Some more things that also need documenting.
> 
> Yes, I agree.  If you find out the answers to any of the questions, 
> please provide a patch.

Well, since it's a GCC extension, I guess we get to make the rules.  In 
general, I think we should restrict as far as possible what can be 
expected.

> 
> > 3) Do addresses of empty structures compare equal?
> 
> That's a logical consequence of them having size 0; if you have
> 
> struct empty {};
> 
> struct empty empty_array[2];
> 
> then (empty_array + 0) == (empty_array + 1)

That's reasonable, but can the address compare equal to an object of 
another type?

We should also point out that taking the difference of two empty pointers 
is unspecified (and will normally cause a division by zero error) -- 
unless, that is, we want to make this return the difference in bytes, as 
we would for a void * pointer.

Finally, there's another one I've thought of:

What is the size of

struct a {
  int x: 1;
  struct empty {} y;
  int z: 1;
};

is it sizeof (int) or 2 * sizeof (int)?

R.




More information about the Gcc-patches mailing list