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]

Re: Empty structures: Legal as GNU extension?


Horst von Brand wrote:
> 
> It just so happens that the Linux kernel uses empty structures [...]
> The idea is to have something like:
> 
> struct empty {};
> 
> struct something {
>   int a, couple, of;
>   double random, fields;
>   struct empty nothing;
>   struct do_throw in, some, more, stuff;
> };
> 
> struct something whatever = {0, 0, 0, 1.0, 2.7, {}, {...}, ...};
> 
> and have the 'nothing' field using no space. I just double-checked here on
> sparc-sun-solaris-2.5.1 with egcs-19980727, and it does exactly that.
> 
> Is the manual missing this (quite useful!) extension, is this whole idea
> stupid, is the compiler broken and accepting something it should not?

If support for empty structs isn't documented, it might go away.

Empty structs are allowed in Standard C++, but might not be really empty.
In Egcs-1.1, with -fnew-abi, they are whenever it's allowed.  (Two objects 
of the same type can't have the same address, so sometimes padding is 
needed.)  Of course this fact isn't very useful for Linux kernel coding 
*quite* yet.  Next year, who knows?

Nathan Myers
ncm@cantrip.org


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