Programming in C

(Barry) #1
436 Appendix A C Language Summary

[1].word = "aardvark", [1].def = "a burrowing African mammal",
[2].word = "aback", [2].def = "to startle"
};
or equivalently like this:
struct entry
{
char *word;
char *def;
} dictionary[1000] = {
{ {.word = "a", .def = "first letter of the alphabet" },
{.word = "aardvark", .def = "a burrowing African mammal"} ,
{.word = "aback", .def = "to startle"}
};
An automatic structure variable can be initialized to another structure of the same type
like this:
struct date tomorrow = today;
This declares the datestructure variable tomorrowand assigns to it the contents of the
(previously declared) datestructure variable today.
AmemberDeclarationthat has the format
type fieldName: n
defines a fieldthat is nbits wide inside the structure, where nis an integer value. Fields
can be packed from left to right on some machines and from right to left on others. If
fieldNameis omitted, the specified number of bits are reserved, but cannot be refer-
enced. If fieldNameis omitted and nis 0 ,the field that follows is aligned on the next
storage unitboundary, where a unitis implementation-defined.The type of field can be
_Bool,int,signed int, or unsigned int. It is implementation-defined whether an int
field is treated as signedor unsigned.The address operator (&) cannot be applied to a
field, and arrays of fields cannot be defined.

4.3.3 Unions
The general format for declaring a union is as follows:
union name
{
memberDeclaration
memberDeclaration
...
} variableList;
This defines a union called namewith members as specified by each
memberDeclaration. Each member of the union shares overlapping storage space, and
the compiler takes care of ensuring that enough space is reserved to contain the largest
member of the union.

20 0672326663 AppA 6/10/04 2:01 PM Page 436

Free download pdf