uunniioonn -- C Keyword

Multiply declare a variable

A uunniioonn defines an area of storage that can accept any one of several types
of  data.  In  effect, it  is a  multiple declaration  of a  variable.  For
example, a uunniioonn may be declared to consist of an iinntt, a ddoouubbllee, and a cchhaarr
*. Any one of these three  elements can be held by the uunniioonn at a time, and
will be handled appropriately by it.  For example, the declaration

union {
    int number;
    double bignumber;
    char *stringptr;
} example;

allows eexxaammppllee  to hold either  an iinntt, a  ddoouubbllee, or a pointer  to a cchhaarr,
whichever is needed at the time.   All of these have the same address.  The
elements of  a uunniioonn are accessed  like those of a  ssttrruucctt: for example, to
access nnuummbbeerr from the above example, type eexxaammppllee.nnuummbbeerr.

uunniioonns are  helpful in dealing  with heterogeneous data,  especially within
structures; however,  you are  responsible for  keeping track of  what data
type the uunniioonn  is holding at any given time.   Passing a ddoouubbllee to a uunniioonn
and then reading the uunniioonn as though it held an iinntt will yield results that
are unpredictable, and probably unwelcome.

_E_x_a_m_p_l_e
For an example  of how to use a uunniioonn in  a program, see the entry for bbyyttee
oorrddeerriinngg.

_S_e_e _A_l_s_o
CC kkeeyywwoorrddss, iinniittiiaalliizzaattiioonn, ssttrruucctt, ssttrruuccttuurree
ANSI Standard, section 3.1.2.5, section 3.5.2.1
