Re: Why do gcc support empty struct extension for?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for your further comment, especially on the standard size of pointer.

So the pointer of the empty struct definition always has a standard
size just like any other pointer type, we can use this pointer to
refer to a "complete struct definition" known only by private module.

We still need the empty struct definition to tell the compiler about
the "hidden/private" content of such struct use in current module.

On Fri, Oct 17, 2008 at 12:08 AM, Michael Meissner
<meissner@xxxxxxxxxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxxxxxxxxx
>



-- 
Regards,
   Chong, Tian Teck
   tiande@xxxxxxxxx

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux