Getting action on your favorite D issues
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Jun 5 23:53:28 UTC 2020
On Fri, Jun 05, 2020 at 11:57:39PM +0200, ag0aep6g via Digitalmars-d wrote:
[...]
> 2) "bool can be both true and false"
> https://issues.dlang.org/show_bug.cgi?id=20148
>
> This one is just silly.
[...]
Nah, it's not silly, it's just that DMD's backend produces code that
exhibits quantum uncertainty:
-----------------
bool schrodingersCat() @safe {
union Box { bool b; int spin; }
Box u;
u.spin = 2;
return u.b;
}
void main() @safe {
import std.stdio;
bool b = schrodingersCat();
if (b) writeln("alive");
if (!b) writeln("dead");
}
-----------------
Output:
-----------------
alive
dead
-----------------
:-D
Unfortunately, LDC's backend seems a lot more classical, as the above
code produces this output with absolute certainty:
Output:
-----------------
dead
-----------------
Truly, DMD's backend is in the bright future of strange and wonderful
quantum effects, whereas LDC is clearly still stuck in the antiquated
classical past. ;-)
T
--
Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.
More information about the Digitalmars-d
mailing list