mikroC - C Compiler for Microchip PIC microcontrollers
Enumerations
An enumeration data type is used for representing an abstract, discreet set of val-
ues with appropriate symbolic names.
Enumeration Declaration
Enumeration is declared like this:
enum tag { enumeration-list };
Here,
of discreet values, enumerators. The enumerators listed inside the braces are also
known as enumeration constants. Each is assigned a fixed integral value. In the
absence of explicit initializers, the first enumerator is set to zero, and each suc-
ceeding enumerator is set to one more than its predecessor.
Variables of
example, the following declaration
enum colors {black, red, green, blue, violet, white} c;
establishes a unique integral type,
enumerators with constant integer values (
variable of an enumerated type can be assigned any value of type
checking beyond that is enforced. That is:
c = red;
c = 1;
With explicit integral initializers, you can set one or more enumerators to specific
values. The initializer can be any expression yielding a positive or negative integer
value (after possible integer promotions). Any subsequent names without initializ-
ers will then increase by one. These values are usually unique, but duplicates are
legal.
page
62
is an optional name of the enumeration;
tag
type are declared same as variables of any other type. For
enum
// OK
// Also OK, means the same
MikroElektronika: Development tools - Books - Compilers
enumeration-list
, a variable
of this type, and a set of
colors
c
,
black = 0
red = 1
mikroC
making it simple...
is a list
, ...). In C, a
– no type
int
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?