Mixing operations with signed and unsigned types
Ellery Newcomer
ellery-newcomer at utulsa.edu
Tue Jul 6 18:32:52 PDT 2010
On 07/06/2010 07:05 PM, Stewart Gordon wrote:
> 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!
For enforcing a non-negative constraint, that is brain damaged.
Semantically, the two are very different.
int i;
assert(i >= 0);
says i can cross the 0 boundary, but it's an error if it does, i.e.
programmer doesn't need to be perfect because it *does get caught*
(extreme instances notwithstanding).
uint i;
says i cannot cross the 0 boundary, but it isn't an error if it does.
programmer needs to be perfect and error doesn't get caught (unless what
you're using it for can do appropriate bounds checking).
>
> Comparison - how do you mean?
>
> Stewart.
Mmmph. Just signed/unsigned, I guess (I was thinking foggily that
comparison intrinsically involves subtraction or something like that)
More information about the Digitalmars-d-learn
mailing list