|
|
The basic types and their sizes are:
Each of char, short, int, and long may be prefixed with signed or unsigned. A type specified with signed is the same as the type specified without signed except for signed char on the 3B2. (char on the 3B2 has only non-negative values.)
The compiler may place an object declared const in read-only memory. The program may not change its value and no further assignment may be made to it. An explicit attempt to assign to a const object will provoke an error.
volatile advises the compiler that unexpected, asynchronous events may affect the object so declared, and warns it against making assumptions. An object declared volatile is protected from optimization that might otherwise occur.
This keyword has no code generation effects in this implementation.
A structure is a type that consists of a sequence of named members. The members of a structure may have different object types (as opposed to an array, whose members are all of the same type). To declare a structure is to declare a new type. A declaration of an object of type struct reserves enough storage space so that all of the member types can be stored simultaneously.
A structure member may consist of a specified number of bits, called a bit-field. The number of bits (the size of the bit-field) is specified by appending a colon and the size (an integral constant expression, the number of bits) to the declarator that names the bit-field. The declarator name itself is optional; a colon and integer will declare the bit-field. A bit-field must have integral type. The size may be zero, in which case the declaration name must not be specified, and the next member starts on a boundary of the type specified. For example:
char :0means ``start the next member (if possible) on a char boundary.''
A named bit-field number that is declared with an explicitly unsigned type holds values in the range
0 - (2[n] -1)
where n is the number of bits. A bit-field declared with an explicit signed types holds values in the range
-2[n-1] - (2[n-1] -1)
A bit-field declared neither explicitly signed nor unsigned will hold values in one of the two ranges, depending on the machine. Consult specific Application Binary Interface Processor Supplement to determine which of the two ranges are correct for a specific processor.
An optional structure tag identifier may follow the keyword struct. The tag names the type of structure described, and may then be used with struct as a shorthand name for the declarations that make up the body of the structure. For example:
struct t { int x; float y; } st1, st2;
Here, st1 and st2 are structures, each made up of x, an int, and y, a float. The tag t may be used to declare more structures identical to st1 and st2, as in:
struct t st3;
A structure may include a pointer to itself as a member; this is known as a ``self-referential structure''.
struct n { int x; struct n *left; struct n *right; };As a special case, the last member of a struct can be an array with no length.
A union is an object that may contain one of several different possible member types. A union may have bit-field members. Like a structure, declaring a union declares a new type. Unlike a structure, a union stores the value of only one member at a given time. A union does, however, reserve enough storage to hold its largest member.
An enumeration is a unique type that consists of a set of constants called enumerators. The enumerators are declared as constants of type int, and optionally may be initialized by an integral constant expression separated from the identifier by an = character.
Enumerations consist of two parts:
enum color {red, blue=5, yellow};color is the tag for this enumeration type. red, blue, and yellow are its enumeration constants. If the first enumeration constant in the set is not followed by an =, its value is 0. Each subsequent enumeration constant not followed by an = is determined by adding 1 to the value of the previous enumeration constant. Thus yellow has the value 6.
enum color car_color;declares car_color to be an object of type enum color.