Structure declarations can appear in a number of different
scopes, but they are most easily understood when declared at file scope.
DerivedName ::= SimpleTypeName | ‘bitfield’ | IdentifierName
StructureDeclaration ::= StructKeyword S IdentifierName? S? (':'
S? DerivedName)? S? '{' S? StructureDefinition S? '}' S? ';'
The first identifier, if it appears, uniquely identifies a structure
type. The name is an identifier that has
not appeared earlier in the file as a construct name, an enumerated
constant block name, an enumerated constant name,
a global variable name, or a global function name.
If the first identifier is absent from the declaration, the
compiler chooses a unique name. Anonymous declaration of structures at
file scope is not recommended, but it can be done.
The derived name is optional. The following rules apply
for a derived name:
-
Absent from declaration: Structure is not derived from any
other type. At least one member variable declaration
must appear in the definition. Methods in the definition are
optional.
-
Another non-derived-from-simple structured type: Structure is
derived from another structured type. This structure must be previously
declared. The new structure inherits a copy of
all the base structure’s member variables and member
functions. For this reason, it is possible for the definition
to be completely empty, although it can have additional members.
-
A simple type: Structure is derived from a simple type.
The definition cannot have member variables or member functions,
but can have an enumerated type association.
-
A derived-from-simple structured type: This is equivalent to
derivation from a simple type. The derived structure does not
inherit the enumerated type association, if present in the base
structure.
-
The ‘bitfield’ keyword: This makes the structure into a bit
field structure. At least one member variable declaration
must appear in the definition. Methods in the definition are
optional.
It is not possible to derive a structure from a bit field structure.
See also: [Global variable
declarations] [Global function declarations]
[Enumerated constant block declarations]
[Structure declarations] [Block
declarations] [List declarations]
|