Apparently unsigned types really are necessary

Marco Leise Marco.Leise at gmx.de
Sun Jan 22 04:40:08 PST 2012


Am 22.01.2012, 10:44 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:

> On Sunday, January 22, 2012 10:31:17 Marco Leise wrote:
>> Am 22.01.2012, 08:23 Uhr, schrieb bcs <bcs at example.com>:
>> > Rename them bits{8,16,32,64} and make the current names aliases.
>>
>> So everyone uses int, and we get messages like: "This program currently
>> uses -1404024 bytes of RAM". I have strong feelings against using signed
>> types for variables that are ever going to only hold positive numbers,
>> especially when it comes to sizes and lengths.
>
> Whereas others have string feelings about using unsigned types for much  
> of
> anything which isn't intended for using bitshifts with. Lots of bugs are
> caused by the use of unsigned integral values. I know that Don wishes  
> that
> size_t were signed and thinks that it's horrible that it isn't. I  
> suspect that
> you will find more people who disagree with you than agree with you on  
> this.
>
> Now, whether having bits8, bits16, etc. is a good idea or not, I don't  
> know,
> but there are a lot of programmers who don't particularly like using  
> unsigned
> types for normal arithmetic, regardless of what values the variable  
> holds.
>
> - Jonathan M Davis

I heard that in the past, but in my own experience using unsigned data  
types, it did not cause any more bugs. OTOH, textual output is more  
correct and I find code easier to understand, if it is using the correct  
'class' of integers. But this "a lot of programmers who don't particularly  
like using unsigned types" must come from somewhere. Except for existing  
bugs in the form of silent under-/overflows that do not appear alarming in  
a debugger due to their signedness, I've yet to see a convincing example  
of real world code, that I would write this way and is flawed due to the  
use of uint instead of int. Or is this like spaces vs. tabs? 'Cause I'm  
also a tab user.


More information about the Digitalmars-d mailing list