Footguns
Footguns
Posted Jul 11, 2021 16:00 UTC (Sun) by Wol (subscriber, #4433)In reply to: Footguns by khim
Parent article: Rust for Linux redux
> This goes so far beyond the abilities of someone to reason about the program it's not funny.
This is the problem with tri-value logic. Look at how SQL handles NULL, for example. By definition, " NULL || !NULL = NULL ".
Although " b || !b " should translate into " known or not known " which one would expect to be true, depending on your definition of "not known", or NULL, or uninitialised ...
Cheers,
Wol
Posted Jul 11, 2021 16:10 UTC (Sun)
by khim (subscriber, #9252)
[Link]
It's C, not SQL. And valid They had to specifically add said trilogic to the code and introduce special “poison” (the name is telling, isn't it?) value to the set of “normal” This doesn't look like a “mere accident” to me, more like an act of sabotage. P.S. GCC does such optimizations a bit differently. Instead of treating undefined value as special “poison” value with trilogic it just assigns arbitrary value to it and then does the usual constant propagation and other such optimizations. This produces almost the same speedup without making user angry.
> Although " b || !b " should translate into " known or not known " which one would expect to be true, depending on your definition of "not known", or NULL, or uninitialised ...
Footguns
int
doesn't have a value which can lead to this three-way logic (float
does, BTW, I wouldn't be much surprised to see the exact same example with floats: (f == 0.0) || (f != 0.0)
can be false in a program without any UB).int
values to achieve that effect.