implicit ubyte casting

Moritz Warning moritzwarning at web.de
Fri Oct 2 08:11:00 PDT 2009


On Fri, 02 Oct 2009 16:25:01 +0200, Don wrote:

> Brad Roberts wrote:
>> On Thu, 1 Oct 2009, Saaa wrote:
>> 
>>> I think is very bug-prone, isn't it obvious iub should be -5?
>>>
>>> ubyte ub = 5;
>>> int iub = -ub; // iub now is 251
>>>
>>> What is the reasoning to do it this way?
>> 
>> The inclusion of the 'int' part obscures what I think the real problem
>> is..
>> 
>>    Does it make sense to use uniary-minus on a unsigned type?
>> 
>> My answer.. no.
> 
> 
> I agree. But you don't actually need unary minus to see the problem:
> 
> import std.stdio;
> 
> void main()
> {
>    uint a = 0;
>    uint b = 5;
>    long ib =  a - b;
>    writefln("%s", ib); // prints: 4294967291
> }

I feel like walking on the edge of a cliff all time without noticing. :>


More information about the Digitalmars-d-learn mailing list