[TUHS] To NDEBUG or not to NDEBUG, that is the question
Arnold Robbins via TUHS
tuhs at tuhs.org
Sun Oct 19 17:12:33 AEST 2025
Dan Cross <crossd at gmail.com> wrote:
> One must question whether `assert` is the right thing or not, though;
> as an interface, it's pretty limited: a thing can either be true or
> not, but any surrounding information is not preserved; for example,
> one often wants to assert whether two things are equal, but if they
> are not, it's often very useful to know what the actual values are:
> `assert` doesn't give you that.
It can be done, it's just not pretty:
assert(answer == 42 ? true :
fprintf(stderr, "answer = %d, expected 42\n", answer),
fflush(stderr), false);
Note the use of the comma operator. The joys of Obfuscated C. :-)
(I do get your main point.)
Arnold
More information about the TUHS
mailing list