why implicitly allowing compare ubyte and byte sucks

Don nospam at nospam.com
Thu Jun 11 19:48:36 PDT 2009


Frits van Bommel wrote:
> Don wrote:
>> For bonus points:
> [end of message]
> 
> I guess nobody'll be getting those bonus points then... :P
<g>

For bonus points:
Code like the following is also almost certainly a bug:
byte b = -1;
if (b == 255)  ... // FALSE!

When variable of byte or short type is compared with a positive literal 
of value > byte.max or short.max respectively, or when an ubyte or 
ushort is compared with a negative literal, it's pretty much the same 
situation.
Flagging an error for this situation would typically reveal the root 
cause: b should have been 'ubyte', not 'byte'.




More information about the Digitalmars-d mailing list