dmd-2.067.0-b1

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 13 04:38:07 PST 2015


On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote:
> This is a bug?
>
> import std.stdio;
>
> void main() {
>     int a = 0;
>
>     writeln( (a < 10) ? a = 1 : a = 2 );    // prints 2
>
>     writeln( (a < 10) ? a = 1 : (a = 2) );  // prints 1
> }
>
> Even C++ output:
> 1
> 1

About 2 years ago, I had a problem with similar structure.

My guess is that the first one is accepted as this.

((a < 10) ? a = 1 : a)   =   ( 2 )

Thereby it gives this result. Vague definitions are always error 
prone.


More information about the Digitalmars-d-learn mailing list