Versions Compared

Key

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

...

  • 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

const-qualified objects allows the programmer to take the address of the object.

Code Block

const int max = 15;
int a[max]; /* invalid declaration outside of a function */
const int *p;

p = &max; /* a const-qualified object can have its address taken */

Most C compilers allocate memory for const-qualified objects.

Also, const-qualified integers cannot be used in locations where an integer constant is required, such as the value of a case constant.

Enumeration Constants

An enumeration constant is a member of an enumeration. 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.

Code Block

enum { max = 15 };
int a[max]; /* OK */
const int *p;

p = &max; /* error: '&' on constant */

Object-like Macros

A preprocessing directive of the form:

...

Wiki Markup
\[[Henricson 92|AA. C References#Henricson 92]\] Chapter 10, "[Constants|http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap10.html]"
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.7, "Declarations"
\[[ISO/IEC PDTR 24772|AA. C References#ISO/IEC PDTR 24772]\] "BRS Leveraging human experience"
\[[Saks 01|AA. C References#Saks 01]\] Dan Saks. [Symbolic Constants|http://www.embedded.com/story/OEG20011016S0116].  Embedded Systems Design. November, 2001.
\[[Saks 02|AA. C References#Saks 02]\] Dan Saks. [Symbolic Constant Expressions|http://www.embedded.com/story/OEG20020124S0117]. Embedded Systems Design. February, 2002.
\[[Summit 05|AA. C References#Summit 05]\] [Question 10.5b|http://c-faq.com/cpp/constvsdefine.html]

...

DCL05-A. Use typedefs to improve code readability      02. Declarations and Initialization (DCL)       DCL07-A. Include the appropriate type information in function declarators