Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.  However, for integer constants, it is preferable to use an enumeration constant instead of a const-qualified object, as this eliminates the possibility of taking the address of the integer constant and does not require that storage is allocated for the value.

Unfortunately, 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 (except in the case of variable length arrays)
  • value of an enumeration constant
  • value of a case constant.

If any of these are required, then an integer constant (an rvalue) must be used.

...