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);
|