Why do gcc support empty struct extension for?
tiande
tiande@gmail.com
Thu Oct 16 17:29:00 GMT 2008
Yes, it is great to know the reason behind a decision in the C
Standard (fix size pointer for unknown structure) and it is cool to
know a people who is involving in the process answering my post :) The
DG machine example describes the scenario to me vividly. Thank you!
And now, I understand why Brian and you previously said this feature
is ISO C complaint but some other info in the internet said not.
struct foo {} is not, but struct bar is.
On Fri, Oct 17, 2008 at 12:50 AM, MICHAEL R. MEISSNER
<meissner@linux.vnet.ibm.com> wrote:
>
> On Fri, 2008-10-17 at 00:28 +0800, tiande wrote:
> > 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.
>
> Yes. When the original C90 standard came out, there were several
> implementations of C on machines that had different sizes or internal
> formats of pointers.
>
> For the early part of the standard process, I was representing the Data
> General corporation whose initial machine was a 16-bit machine that only
> had word pointers, and later added byte pointers by shifting the word
> pointer left by one bit (the word pointer format used the top bit for an
> indirection bit). On a DG machine, structure pointers were always word
> pointers, even if the only items in a structure were bytes due to the
> requirement of supporting pointers to unknown structures.
>
> > We still need the empty struct definition to tell the compiler about
> > the "hidden/private" content of such struct use in current module.
>
> My reading of the grammar in section 6.7.2.1 of the ISO C99 standard is
> that it is not standards compliant for GCC to accept struct foo {},
> since struct-declaration-list must contain at least one
> struct-declaration, and struct-declaration must contain at least one
> declarator. GCC does not seem to warn about this.
>
--
Regards,
Chong, Tian Teck
tiande@gmail.com
--
Regards,
Chong, Tian Teck
tiande@gmail.com
More information about the Gcc-help
mailing list