is this intended behavior?

Don Clugston dac at nospam.com.au
Tue Apr 10 12:40:13 PDT 2007


Derek Parnell wrote:
> On Mon, 09 Apr 2007 15:01:56 -0400, Frank Malone wrote:
> 
>> dmd v1.010
>>
>> import std.stdio;
>> void main() {
>>         uint a = 3;
>>         ubyte b = 3;
>>         int c = -1;
>>         writefln(c < a ? "true" : "false"); // outputs false
>>         writefln(c < b ? "true" : "false"); // outputs true
>> }
> 
> Yes, kind of ... it is undefined behaviour ... the compiler doesn't know
> what to do so it does something dumb instead. I believe that a warning
> (a.k.a "error" in Walter-speak) should be issued by the compiler.

I agree.
I think we should seriously consider the possibility that literals 
should be treated differently to variables, as regards signed-unsigned 
mismatches.
* If the value fits in the range 0..int.max, it should be implicitly 
convertible to int, or to uint. --> 100% guaranteed safe.
* If it is outside that range, an error should be issued, since it is 
definitely a bug.

My feeling is, that this would eliminate most of the annoying & useless 
signed/unsigned mismatch warnings, and catch many of the real bugs.




More information about the Digitalmars-d mailing list