HP C A.06.05 Reference Manual

Data Types and Declarations
Structure and Union Specifiers
Chapter 350
separate name space reserved for tags. Thus, a structure tag may have the same spelling as a
structure member or an ordinary identifier. Structure tags also obey the normal block scope
associated with identifiers. Another tag of the same spelling in a subordinate block may hide a
structure tag in an outer block.
A struct or union declaration has two parts: the structure body, where the members of the
structure are declared (and possibly a tag name associated with them); and a list of
declarators (objects with the type of the structure).
Either part of the declaration can be empty. Thus, you can put the structure body declaration
in one place, and use the struct type in another place to declare objects of that type.
For example, consider the following declarations:
struct s1 {
int x;
float y;
};
struct s1 obj1, *obj2;
The first example declares only the struct body and its associated tag name. The second
example uses the struct tag to declare two objects — obj1 and obj2. They are, respectively, a
structure object of type struct s1 and a pointer object, pointing to an object of type struct
s1.
This allows you to separate all the struct body declarations into one place (for example, a
header file) and use the struct types elsewhere in the program when declaring objects.
Consider the following example:
struct examp {
float f; /* floating member */
int i; /* integer member */
}; /* no declaration list */
In this example, the structure tag is examp and it is associated with the structure body that
contains a single floating-point quantity and an integer quantity. Note that no objects are
declared after the definition of the structure's body; only the tag is being defined.
A subsequent declaration may use the defined structure tag:
struct examp x, y[100];
This example defines two objects using type struct examp. The first is a single structure
named x and the second, y, is an array of structures of type struct examp.