COHERENT manpages

This page displays the COHERENT manpage for enum [Declare a type and identifiers].

List of available manpages
Index


enum -- C Keyword

Declare a type and identifiers

An enum  declaration is  a data  type whose syntax  resembles those  of the
struct and union declarations.  It lets you enumerate the legal value for a
given variable.  For example,

    enum opinion {yes, maybe, no} GUESS;

declares type opinion can have one  of three values: yes, no, and maybe. It
also declares the variable GUESS to be of type opinion.

As with a struct or union declaration, the tag (opinion in this example) is
optional;  if present,  it  may be  used in  subsequent declarations.   For
example, the statement

    register enum opinion *op;

declares a register pointer to an object of type opinion.

All enumerated  identifiers must be distinct from  all other identifiers in
the program.   The identifiers  act as constants  and can be  used wherever
constants are appropriate.

COHERENT assigns  values to  the identifiers  from left to  right, normally
beginning  with zero  and increasing  by  one.  In  the above  example, the
values of yes, no, and maybe are set, respectively, to one, two, and three.
The values often are ints, although if the range of values is small enough,
the enum will  be an unsigned char. If an  identifier in the declaration is
followed by  an equal sign and  a constant, the identifier  is assigned the
given value,  and subsequent  values increase by  one from that  value; for
example,

    enum opinion {yes=50, no, maybe} guess;

sets the  values of the identifiers  yes, no, and maybe to  50, 51, and 52,
respectively.

See Also

C keywords
ANSI Standard, §6.5.2.2