Mixing operations with signed and unsigned types

Stewart Gordon smjg_1998 at yahoo.com
Tue Jun 29 18:48:15 PDT 2010


bearophile wrote:
> Stewart Gordon:
>> http://d.puremagic.com/issues/show_bug.cgi?id=259
> 
> I have added my vote there a lot of time ago. I think Andrei says 
> that fixing this is unworkable, but I don't know why. If you make 
> this an error and at the same time turn array indexes/lengths into 
> signed values, you don't have that many unsigned values in normal D 
> programs, so you need very few casts and it becomes workable.

That's probably because many people neglect the unsigned types, instead 
using the signed types for array indices and the like.

Array indices are actually of type size_t.  Effectively, what you seem 
to be suggesting is that size_t be the same as ptrdiff_t.

There is, however, another problem: signed types convert implicitly to 
unsigned types, though they do generate a warning if compiled with -w 
(except peculiarly for int/uint).  Removing this implicit conversion 
would break certain existing code that uses signed types where it should 
be using unsigned.  If we also change array indices to be signed, it 
would break that code that sensibly uses unsigned types, which is 
probably worse.

Stewart.


More information about the Digitalmars-d-learn mailing list