...
In general, it is preferable to declare immutable values as const
-qualified objects rather than as macro definitions. Using a const
declared value means that the compiler is able to check the type of the object, the object has scope, and (certain) debugging tools can show the name of the object. Const-qualified objects cannot be used where compile-time integer constants are required, namely to define the:
- size of a bit-field member of a structure
- size of an array
- value of an enumeration constant
- value of a
case
constant.
...
Delcaring immutable integer values as const-qualified objects still allows the programmer to take the address of the object. Also, the constant cannot be used in locations where an an integer constant is required, such as the size of an array.
...
This compliant solution uses an enum
rather than a const-qualified object or a macro definition.
...