Versions Compared

Key

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

...

Static assertion is also a new facility in the C++ 0X draft standard and take the form:

Code Block
static_assert(constant-expression, string-literal);

Wiki Markup
According to the C+\+ 0X draft standard \[[Becker 08|AA. C References#Becker 08]\], the {{constant-expression}} in a static assert declaration is a constant expression that can be converted to {{bool}} at compile time. If the value of the expression when converted is true, the declaration has no effect.  Otherwise the program is ill-formed, and a diagnostic message (which includes the text of the {{string-literal}}) is issued at compile time.  For example:

Code Block
static_assert(sizeof(int) <= sizeof(void*), "sizeof(int) <= sizeof(void*)"); /* Passes */
static_assert(sizeof(double) <= sizeof(int), "sizeof(double) <= sizeof(int)"); /* Fails */

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[Becker 08|AA. C References#Becker 08]\] 
\[[Eckel 07|AA. C References#Eckel 07]\]
\[[ISO/IEC 9899-1999|AA. C References#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"
\[[Klarer 04|AA. C References#Klarer 04]\]
\[[Saks 05|AA. C References#Saks 05]\]
\[[Saks 08|AA. C References#Saks 08]\]

...