•  Back 
  •  C Language 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help 
  •  Show info about hypertext 
  •  View a new file 
Topic       : C-Language Documentation
Author      : John Kormylo
Version     : C.HYP 1.0
Subject     : Documentation/C-Language
Nodes       : 233
Index Size  : 6362
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : en
@default    : 
@help       : Help
@options    : +g -i -s +x +z -t4
@width      : 75
View Ref-File[ Data Types: enum ]

Defines a new data type, 'enum <name>'.  Syntax:

  enum <name> { <list of names> };

where <name> is the enum name and <list of names> is a list of items
of the form

  <cname> [ = <constant> ] , ...

where <cname> is a new constant name and <constant> is an integer
constant.

This statement assigns values to the constant names in the list
starting with 0 and incrementing by one.

By using the '= <constant>' option one can change the starting number
or put a gap in the series.

Example:

  enum numbers {One=1, Two, Three=4, Four};

accomplishes the same thing as

  const int One = 1, Two = 2, Three = 4, Four = 5;

except that One...Four are of the type (enum numbers) rather than
(const int).

One can now define enum variables using

  [<qualifier>] [<class>] enum <name> <variable> [= <enum constant> ]
    [, ...] ;

where <qualifier> is a type qualifier,
<class> is a storage class,
<variable> is a new variable name, and
<enum constant> is taken from <list of names>; e.g.,

  enum numbers x = One;

Once can also combine an enum definition and variable definition into
one statement (in which case <name> is optional).  One can similarly
combine an enum definition and a typedef statement.

See also Names, Constants and Variables.