Assertions are a valuable diagnostic tool for finding and eliminating software defects that may result in vulnerabilities. (See 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 useful 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.
...
The constant expression shall be an integer constant expression. If the value of the constant expression compares unequal to 0, the declaration has no effect. Otherwise, the constraint is violated and the implementation shall produce a diagnostic message that includes the text of the string literal, except that characters not in the basic source character set are not required to appear in the message.
This It means that if constant-expression
is true, nothing will happen. However, if constant-expression
is false, an error message containing string-literal
will be output at compile time.
...