is this intended behavior?

Pragma ericanderton at yahoo.removeme.com
Tue Apr 10 08:18:16 PDT 2007


Dan wrote:
> Tom S Wrote:
> 
>> John Demme wrote:
>>> unknown wrote:
>>>
>>>> Frank Malone Wrote:
>>>>>         writefln(c < a ? "true" : "false"); // outputs false
> 
> What it appears to be doing incorrectly is attempting to convert -1 to an unsigned value to compute the comparison; which should produce uint.max; while the ubyte may be converting to a uint as well.
 >
 > (int < ubyte) ought to be reasonable to use.  The fact it isn't never occurred to me, and would demonstrate that the 
language is still lacking in a couple quite fundamental areas.

What makes this a big WTF, is that the conversion from int to uint is done on the opposite side of the comparison as the 
conversion from ubyte to int.  It's almost as if the compiler tries to implicitly convert the right-hand side, fails, 
then attempts to implicitly convert the left, and passes.

IMO, behavior that complicated (and subtle!) should be defined, and documented if not labeled a bug.  Either that, or it 
should force a cast() in cases where mixed types can yield unpredictable results.


-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list