Getting action on your favorite D issues

Meta jared771 at gmail.com
Sat Jun 6 03:40:24 UTC 2020


On Saturday, 6 June 2020 at 00:25:15 UTC, H. S. Teoh wrote:
> On Fri, Jun 05, 2020 at 04:53:28PM -0700, H. S. Teoh via 
> Digitalmars-d wrote:
>> 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:
> [...]
>
> For even more quantum fun:
>
> ----------
> bool schrodingersCat() @safe {
> 	import std.random;
> 	union Box { bool b; int state; }
> 	Box u;
> 	u.state = uniform(2, int.max);
> 	return u.b;
> }
> void main() @safe {
> 	import std.stdio;
> 	bool b = schrodingersCat();
> 	if (b) writeln("alive");
> 	if (!b) writeln("dead");
> }
> ----------
>
> With LDC, this code will output either "alive" or "dead" with a 
> roughly 50% probability of each.  So it's a classical observer.
>
> With DMD, however, this code will perceive the quantum 
> superimposition directly and output both "alive" and "dead" 
> every time.
>
> :-D
>
> //
>
> OK, I'll stop now. :-P
>
>
> T

The linked defect, and the issue you posted, don't really make 
sense to me. They both have UB; reading from an uninitialized 
variable (= void), or writing to one member of a union and 
reading from the other. Invoke Undefined Behaviour and you get... 
Undefined Behaviour.


More information about the Digitalmars-d mailing list