Assignment in ternary condition operator

JN 666total at wp.pl
Tue Aug 7 19:18:06 UTC 2018


int a, b;

if (a = 3) { }   <- not allowed: Error: assignment cannot be used 
as a condition, perhaps == was meant?

b = a = 3 ? 4 : 5   <- allowed


I believe the second case should be disallowed also. It seems 
illogical, that the first one isn't allowed, but the second one 
is, when the second one is also 'assignment used as condition'. 
Is there a valid usecase for such assignment?


More information about the Digitalmars-d-learn mailing list