This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Why do gcc support empty struct extension for?
- From: Michael Meissner <meissner at linux dot vnet dot ibm dot com>
- To: tiande <tiande at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 16 Oct 2008 12:08:26 -0400
- Subject: Re: Why do gcc support empty struct extension for?
- References: <9b431b940810151856h71ad7ber6879a38ee2af3671@mail.gmail.com> <9b431b940810151902ic22f39cof9c850a30ae51ef7@mail.gmail.com>
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