Why do gcc support empty struct extension for?
Michael Meissner
meissner@linux.vnet.ibm.com
Thu Oct 16 16:09:00 GMT 2008
On Thu, Oct 16, 2008 at 10:02:24AM +0800, tiande wrote:
> In C++ context, I understand that it might be used as base class.
> But I don't understand, what does it for in C context? What is the
> reason we used empty struct in C.
>
> (This is the first time I post in this mailing list and I have search
> through comp.lang.c, gcc mailing list, google to make sure that this
> is not a repeated post)
>
> e.g.
>
> struct foo{};
>
> or just
>
> struct bar;
Using struct bar without a definition has always been part of the C language
(and is part of the C90/C99 standard). Usually you want to use it to declare
pointers to data that is only visible in private modules, i.e.
struct bletch {
int a;
struct bar *private_ptr;
int c;
};
The ISO standard does require that all pointers to structures be the same size
and format, just to allow this usage.
--
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com
More information about the Gcc-help
mailing list