F
Frederick Gotham
Irrespective of whether NDEBUG is defined, must an assertion expression
always be evaluated? For instance, is the following code perfectly OK?
#define NDEBUG
#include <assert.h>
int main(void)
{
int array[5];
int *p = array + 5;
assert(--p);
*p = 3;
return 0;
}
Is it wise to rely on the evaluation of assertion expressions, or would it
be better to move any side-effects to outside of the assertion, such as:
--p; assert(p);
instead of:
assert(--p);
always be evaluated? For instance, is the following code perfectly OK?
#define NDEBUG
#include <assert.h>
int main(void)
{
int array[5];
int *p = array + 5;
assert(--p);
*p = 3;
return 0;
}
Is it wise to rely on the evaluation of assertion expressions, or would it
be better to move any side-effects to outside of the assertion, such as:
--p; assert(p);
instead of:
assert(--p);