This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Empty structures: Legal as GNU extension?
- To: egcs at cygnus dot com
- Subject: Re: Empty structures: Legal as GNU extension?
- From: Nathan Myers <ncm at cygnus dot com>
- Date: Thu, 06 Aug 1998 13:56:40 -0700
- Newsgroups: cygnus.egcs
- Organization: http://www.cantrip.org/
- References: <199808051511.LAA19382.cygnus.egcs@pincoya.inf.utfsm.cl>
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