Download C for AIX User's Guide
Transcript
typedef
A typedef declaration lets you define your own identifiers that can be used in place of type specifiers such
as int, float, and double. The names you define using typedef are not new data types. They are
synonyms for the data types or combinations of data types they represent.
A typedef declaration does not reserve storage.
When an object is defined using a typedef identifier, the properties of the defined object are exactly the
same as if the object were defined by explicitly listing the data type associated with the identifier.
The following statements declare LENGTH as a synonym for int, then use this typedef to declare length,
width, and height as integral variables.
typedef int LENGTH;
LENGTH length, width, height;
The following declarations are equivalent to the above declaration:
int length, width, height;
Similarly, you can use typedef to define a struct type. For example:
typedef struct {
int scruples;
int drams;
int grains;
} WEIGHT;
The structure WEIGHT can then be used in the following declarations:
WEIGHT chicken, cow, horse, whale;
“Type Specifiers” on page 66
“struct (Structures)” on page 95
“int, long, short” on page 81
Data Type Qualifiers
Qualifier
const
Description
Explicitly declares a data object as a data item that cannot
be changed. Its value is set at initialization. You cannot
use const data objects in expressions requiring a
modifiable lvalue. For example, a const data object
cannot appear on the left-hand side of an assignment
statement.
Chapter 6. The C Language
115