[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

8. Enumerations

purpose
Use enumerations for ordinals, that is, values that represent concepts, such as colors, types, shapes, modes, ....

Don't use enumerations for bit masks. Use a collection of #defines instead. Use u or ul suffixes to force the bit masks to be of type unsigned or unsigned long. (Enumeration members are always of type int.)

tags
Each enumeration type should have a tag. A variable declared to be of type enum tag should be used wherever reasonable for storing a value from the enumeration, for documentary purposes, and especially as a function parameter type.

names
When an enumeration is defined within a public header file, include the module's name prefix within each enumeration. If a module defines more than a few enumeration types, add another prefix to identify the particular enumeration type.

Enumeration member names should be in all capitals.

count
Most enumerations should have a final item named prefix_CNT. The value of this item is the number of items in the enumeration, its count. Specify this value explicitly when declaring an array with one element per member of the enumeration, in order to facilitate compiler verification of the array's size.

syntax
Don't follow the final enumeration member name by a comma. ANSI C89 doesn't allow it, though ANSI C99 and many compilers do.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Ben Pfaff on September, 11 2001 using texi2html