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

Rule:  ORG#010Checked automatically with code checker

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


Description:

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");
free(buf);

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


Literature References:
ISC++ Rule 11.1