diff options
author | dj <dj@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-10-08 19:44:53 +0000 |
---|---|---|
committer | dj <dj@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-10-08 19:44:53 +0000 |
commit | 7cb6c162b628563c0a7308ac3bf74b3fb22135ba (patch) | |
tree | 57957d9b9f531e9eefc55ddc7c9826a3fc7e0004 /gcc/doc | |
parent | a45a9a4d05f731e2b3e4d558fca6bdf9b4f45109 (diff) | |
download | gcc-7cb6c162b628563c0a7308ac3bf74b3fb22135ba.tar.gz |
* c-decl.c (grokfield): Make sure the only unnamed fields
we're allowing are either structs or unions.
* doc/extend.texi: Add documentation for the unnamed field
extension.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@46088 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 1ae858e93d4..be659203b15 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -433,6 +433,7 @@ extensions, accepted by GCC in C89 mode and in C++. * Vector Extensions:: Using vector instructions through built-in functions. * Other Builtins:: Other built-in functions. * Pragmas:: Pragmas accepted by GCC. +* Unnamed Fields:: Unnamed struct/union fields within structs/unions. @end menu @end ifset @ifclear INTERNALS @@ -4503,6 +4504,47 @@ that of the @code{unused} attribute, except that this pragma may appear anywhere within the variables' scopes. @end table +@node Unnamed Fields +@section Unnamed struct/union fields within structs/unions. +@cindex struct +@cindex union + +For compatibility with other compilers, GCC allows you to define +a structure or union that contains, as fields, structures and unions +without names. For example: + +@example +struct @{ + int a; + union @{ + int b; + float c; + @}; + int d; +@} foo; +@end example + +In this example, the user would be able to access members of the unnamed +union with code like @samp{foo.b}. Note that only unnamed structs and +unions are allowed, you may not have, for example, an unnamed +@code{int}. + +You must never create such structures that cause ambiguous field definitions. +For example, this structure: + +@example +struct @{ + int a; + struct @{ + int a; + @}; +@} foo; +@end example + +It is ambiguous which @code{a} is being referred to with @samp{foo.a}. +Such constructs are not supported and must be avoided. In the future, +such constructs may be detected and treated as compilation errors. + @node C++ Extensions @chapter Extensions to the C++ Language @cindex extensions, C++ language |