I want to assert that an unsigned int is strictly positive. I was debating between the following two options:
unsigned int i = 1;
assert(i > 0); /*option 1*/
assert(i != 0); /*option 2*/
I found myself stuck in a Buridan's ass dilemma. Is there any reason to prefer one over the other?
assert(i > 0);
is more readable to other programmers that i
is checked for positive integers and including the case for i = 0
.
Note: As Joachim pointed in his comment that keep in mind that if the macro NDEBUG
was defined at the moment <assert.h>
was last included, the macro assert()
generates no code, and hence does nothing at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With