Versions Compared

Key

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

...

const:

  • operates at run time
  • consumes memory (though this is not too important)
  • can't use in compile-time constant expression
  • uses consistent syntax
  • can create pointers to
  • does type checking

Enumeration Constants

Enumeration constant can be used to represent an integer constant expression that has a value representable as an int. Unlike const-qualified objects, enumeration constants do not require that storage is allocated for the value so it is not possible to take the address of an enumeration constant.

...

Compliant Solution (sizeof)

A Frequently it is possible to obtain the desired readability by using a symbolic expression composed of existing symbols rather than by defining a new symbol. For example, a sizeof expression can work just as well as an enumeration constant (see EXP09-A. Use sizeof to determine the size of a type or variable).

...

Wiki Markup
Using the {{sizeof}} expression in this example reduces the total number of names declared in the program, which is almost alwaysgenerally a good idea \[[Saks 02|AA. C References#Saks 02]\].  The {{sizeof}} operator is almost always evaluated at compile time (except in the case of variable length arrays).

...