K
Keith Thompson
James Van Buskirk said:At last! A C programmer to inflict the Question on! Now, what if
true is a const _Bool with internal representation B'00000010'
and var is also an _Bool. Does the assert happen if NDEBUG is not
on?
Since `var = true` is an assignment, yes, the assert will fire.
Let's assume that the `= true` is replaced by `== true` (though it would
be better to omit it altogether and write `assert(var);`).
If there's a visible `#include <stdbool.h>` directive, then `true` is a
macro that expands to 1, so to satisfy your assumptions we have to
assume that the programmer has (foolishly) redefined `true` -- but how?
Converting any scalar value to _Bool yields 0 if the value is equal to
0, 1 if it's not, which makes it difficult to construct a _Bool value
other than 0 or 1.
If you manage do so, it's likely that your program's behavior has become
undefined while doing so, which means the assert happen, or it may not
happen, or the walls might start to bleed.
The simple answer is: Don't do that.
But if you want an answer beyond that, I suggest you show the specific C
code you're asking about.
(Incidentally, B'00000010' is not C syntax, but it's obvious enough what
you mean.)