HP C/iX Reference Manual (31506-90011)

Chapter 3 35
Data Types and Declarations
Structure and Union Specifiers
Structure and Union Specifiers
A structure specifier indicates an aggregate type consisting of a sequence of named
members. A union specifier defines a type whose members begin at offset zero from the
beginning of the union.
Syntax
struct-or-union specifier
:=
struct-or-union [identifier] { struct-declaration-list }
struct-or-union identifier
struct-or-union
::=
struct
union
struct-declaration-list
::=
struct-declaration
struct-declaration-list struct-declaration
struct-declaration
::=
specifier-qualifier-list struct-declarator-list
;
specifier-qualifier-list
::=
type-specifier [specifier-qualifier-list]
type-qualifier [specifier-qualifier-list]
struct-declarator-list
::=
struct-declarator
struct-declarator-list , struct-declarator
struct-declarator
::=
declarator
[declarator] : constant-expression
Description
A structure is a named collection of members. Each member belongs to a name space
associated with the structure. Members in different structures can have the same names
but represent different objects.
Members are placed in physical storage in the same order as they are declared in the
definition of the structure. A member's offset is the distance from the start of the structure
to the beginning of the member. The compiler inserts pad bytes as necessary to insure that
members are properly aligned. For example, if a char member is followed by a float
member, one or more pad bytes may be inserted to insure that the float member begins
on an appropriate boundary.
The HP C Programmer's Guide provides a detailed comparison of storage and alignment
on HP computers.