User manual

202
mikoC PRO for dsPIC
MikroElektronika
With explicit integral initializers, you can set one or more enumerators to specic values. The initializer can be any
expression yielding a positive or negative integer value (after possible integer promotions). Any subsequent names
without initializers will be increased by one. These values are usually unique, but duplicates are legal.
The order of constants can be explicitly re-arranged. For example:
enum colors { black, // value 0
red, // value 1
green, // value 2
blue=6, // value 6
violet, // value 7
white=4 }; // value 4
Initializer expression can include previously declared enumerators. For example, in the following declaration:
enum memory_sizes { bit = 1, nibble = 4 * bit, byte = 2 * nibble,
kilobyte = 1024 * byte };
nibble would acquire the value 4, byte the value 8, and kilobyte the value 8192.
Anonymous Enum Type
In our previous declaration, the identier colors is an optional enumeration tag that can be used in subsequent
declarations of enumeration variables of the enum colors type:
enum colors bg, border; /* declare variables bg and border */
Like with struct and union declarations, you can omit the tag if no further variables of this enum type are required:
/* Anonymous enum type: */
enum { black, red, green, blue, violet, white } color;
Enumeration Scope
Enumeration tags share the same name space as structure and union tags. Enumerators share the same name space
as ordinary variable identiers:
int blue = 73;
{ // open a block
enum colors { black, red, green, blue, violet, white } c;
/* enumerator blue = 3 now hides outer declaration of int blue */
struct colors { int i, j; }; // ILLEGAL: colors duplicate tag
double red = 2; // ILLEGAL: redenition of red
}
blue = 37; // back in int blue scope