This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Empty structures: Legal as GNU extension?
- To: egcs at cygnus dot com
- Subject: Empty structures: Legal as GNU extension?
- From: Horst von Brand <vonbrand at inf dot utfsm dot cl>
- Date: Wed, 05 Aug 1998 11:11:21 -0400
It just so happens that the Linux kernel uses empty structures (as
uniprocessor alternatives for structures that do have contents in the
multiprocessor case, so as to be able not to have different structure
definitions, different code and whatnot for both cases). This does work,
and has worked for ages. This also very clearly isn't ANSI C, AFAIK.
Just empty structure initializers crash the compiler under certain quite
particular circumstances with gcc-2.7.2.3, I reported it to gcc-bugs, but
heard nothing further. The problem was probably fixed in the prehistory of
egcs, as I remember checking against one of the first egcses around on i586
and it worked fine.
I was quite sure to have seen that documented as a GNU extension, but in my
(egcs-19980727) copy of the info manual it isn't mentioned. 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? All
of the above? ;-)
Thanks!
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513