Hi -

meteor.chpl uses cast-to-bool from an integer expression,
like this test code does:

proc foo(x:uint, y:uint)
{
   writeln((x & y):bool);
}

writeln((0x3 & 0x1):bool);
foo(0x3, 0x1);
writeln((0x300 & 0x100):bool);
foo(0x300, 0x100);


I don't see anything in the spec about conversions
*from* uint/int to bool; I'd expect to see that in
section 9.2.1.

So - that begs the question - what is such a program
actually supposed to do?

C99 says "When any scalar value is converted to
_Bool, the result is 0 if the value compares equal
to 0; otherwise, the result is 1"

It appears that our generated C code uses _Bool and
so works in this manner... and that the Chapel
implementation of cast-to-bool for param expressions
also works in this manner.

The LLVM backend does *not* work in this manner..
which I believe is a bug. Either way, the expected behavior
should be documented in the spec.

Thanks,

-michael

------------------------------------------------------------------------------
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to