why implicitly allowing compare ubyte and byte sucks
Lionello Lunesu
lio at lunesu.remove.com
Thu Jun 11 17:02:07 PDT 2009
Walter Bright wrote:
> davidl wrote:
>> It seems that comparing two different operands with different size
>> makes no sense. The compiler should issue an error against that.
>
> Consider:
>
> byte b;
> if (b == 1)
>
> here you're comparing two different sizes, a byte and an int.
> Disallowing such (in its various incarnations) is a heavy burden, as the
> user will have to insert lots of ugly casts.
>
> There really isn't any escaping from the underlying representation of
> 2's complement arithmetic with its overflows, wrap-arounds, sign
> extensions, etc.
Why is "1" an int? Can't it be treated similar to the way string
literals are treated: "a string literal" can be string, wstring and dstring:
dstring test = "Asdf";
int main()
{
return test == "asdf";
}
L.
More information about the Digitalmars-d
mailing list