Assertions are a valuable diagnostic tool for finding and eliminating software defects that may result in vulnerabilities. (See recommendation MSC11-C. Incorporate diagnostic tests using assertions.) The runtime assert()
macro has some limitations, however, in that it incurs a runtime overhead and because it calls abort()
. Consequently, the runtime assert()
macro is only useful for identifying incorrect assumptions and not for runtime error checking. As a result, runtime assertions are generally unsuitable for server programs or embedded systems.
Static assertion is a new facility in the C1X draft standard \ [[Jones 2010|AA. Bibliography#Jones 10]\] and the C+\+ 0X draft standard \ [[Becker 2008|AA. Bibliography#Becker 08] \] and takes the form Wiki Markup
Code Block |
---|
static_assert(constant-expression, string-literal); |
...
Tool | Version | Checker | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||||
|
|
|
|
...
ISO/IEC 9899:1999 Section 6.10.1, "Conditional inclusion," and Section 6.10.3.3, "The ## operator," and Section 7.2.1, "Program diagnostics"
Bibliography
\[[Becker 2008|AA. Bibliography#Becker 08]\]
\[[Eckel 2007|AA. Bibliography#Eckel 07]\]
\[[Jones 2010|AA. Bibliography#Jones 10]\]
\[[Klarer 2004|AA. Bibliography#Klarer 04]\]
\[[Saks 2005|AA. Bibliography#Saks 05]\]
\[[Saks 2008|AA. Bibliography#Saks 08]\] Wiki Markup
[Eckel 2007]
[Jones 2010]
[Klarer 2004]
[Saks 2005]
[Saks 2008]
...