Mixing operations with signed and unsigned types

Stewart Gordon smjg_1998 at yahoo.com
Tue Jul 6 17:05:26 PDT 2010


Ellery Newcomer wrote:
> On 07/05/2010 07:59 AM, Stewart Gordon wrote:
>> bearophile wrote:
>>> Stewart Gordon:
>>>> I can also imagine promoting your mindset leading to edit wars
>>>> between developers declaring an int and then putting
>>>> assert (qwert >= 0);
>>>> in the class invariant, and those who see this and think it's
>>>> brain-damaged.
> 
> As opposed to doing what?

Just using uint, of course!

<snip>
> Another important difference is the point of non-'continuity'
> 
> with a signed integer, that point is *.max/min. Assuming typical usage 
> of integers centers around zero, this point doesn't get hit frequently.
> 
> with an unsigned integer, that point is 0. Assuming the same, this point 
> gets hit much more frequently, which has important implications for 
> subtraction and comparison.

Subtraction - yes, obviously.

Comparison - how do you mean?

Stewart.


More information about the Digitalmars-d-learn mailing list