...
By using the invalid()
function defined above, the function is less likely to modify memory outside its bounds (see MSC11-A. Incorporate diagnostic tests using assertions).
Code Block | ||
---|---|---|
| ||
void incr(int *intptr) { if (invalid( intptr)) { /* handle error */ } *intptr++; } |
...
Since invalid pointers are often indicative of a bug in the program, one can use the assert()
macro to terminate immediately if an invalid pointer is discovered (see MSC11-A. Incorporate diagnostic tests using assertions).
Code Block | ||
---|---|---|
| ||
#include <assert.h> void incr(int *intptr) { assert(!invalid( intptr)); *intptr++; } |
...