...
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 */ |
const
-qualified objects are likely to incur some runtime overhead. [Saks 01b] Most C compilers, for example, allocate memory for const
-qualified objects. const
-qualified objects declared inside a function body will have automatic storage duration. Consequently, if the compiler allocates storage for the object, it will be on the stack and this storage will need to be allocated an initialized each time the containing function is invoked.
Also, const
-qualified integers cannot be used in locations where an integer constant is required, such as the value of a case
constant.
...
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 0101a|AA. C References#Saks 01]\] Dan Saks. [Symbolic Constants|http://www.embedded.com/story/OEG20011016S0116]. Embedded Systems Design. November, 2001. \[[Saks 01b|AA. C References#Saks 02]\] Dan Saks. [Enumeration Constants vs. Constant Objects|http://www.embedded.com/columns/programmingpointers/9900402]. 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] |
...