if (int bar = .. bug or some thing
Adam D. Ruppe
destructionator at gmail.com
Tue Oct 31 04:18:08 UTC 2017
On Tuesday, 31 October 2017 at 04:08:12 UTC, Joel wrote:
> if (int bar = foo() != 0) {
Not a bug, but I do think it is an iffy design.
That is more like:
int bar;
if(bar = (foo() != 0))
so the foo != 0 is evaluated first, which ends up being boolean
true or false, then THAT true/false value is converted to int and
assigned to bar, hence it becomes 0 or 1.
You can't really combine declaration and non-trivial comparison
in a single statement.
More information about the Digitalmars-d-learn
mailing list