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


Richard Henderson wrote:
No, that's not what we want.


struct foo {
#ifdef SMP
long long count;
long lock;
#endif
};

Here, attribute((nopadding)) would leave foo with size 12, instead of the required size 16 when SMP is defined.

We _only_ want to change the zero-size-ness of this struct.
Well, this can handled:

#ifndef SMP
       __attribute__(nopadding)__
#endif

That is not to say whether re-using nopadding for two (related)
purposes would be a good idea or not, but we *could* do so.

Another (wild) idea:  Allow "negative" dizes - or fields that
don't count to the final size:

struct foo {
  int a;
  __size_cutoff_;
  int b;
};

In this case, sizeof(struct foo)==sizeof(int).  If you access a 'b',
it will be actually be access from the *next* field.  This would
be like:

struct foo {
  int a;
  int __b[0];
};

except b is not an array.

Note:  I don't say this is a terribly useful feature - but then some
would say that empty structs aren't terribly useful either.

Then an empty struct is:
struct foo {
  __size_cutoff;
:;
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


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