TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  ORG#010Checked automatically with code checker

Synopsis:Do not let assertions change the state of the program
Severity Level:1
Category:Code Organization


Assertions are used to verify assumptions made during development. For performance reasons it should be possible to remove assert statements from the compiled code by means of conditional compilation. Of course, when state changing statements are removed this way, the program does not work anymore the way it was intended. For example:

// Wrong: allocation not done in release code
char *buf;
assert(buf = (char *) calloc( 20, sizeof(char)));
strcpy(buf, "Hello, World");

// Correct: allocation always done
char *buf;
buf = (char *) calloc( 20, sizeof(char));
assert(buf != nullptr);
strcpy(buf, "Hello, World");