bearophile can say "i told you so" (re uint->int implicit conv)

Steven Schveighoffer schveiguy at yahoo.com
Wed Apr 3 07:54:03 PDT 2013


On Wed, 03 Apr 2013 07:33:05 -0400, Don <turnyourkidsintocash at nospam.com>  
wrote:

> Yeah, but I think that what this is, is demonstrating what a useful  
> concept a positive integer type is. There's huge value in statically  
> knowing that the sign bit is never negative. Unfortunately, using uint  
> for this purpose gives the wrong semantics, and introduces these  
> signed/unsigned issues, which are basically silly.
>
> Personally I suspect there aren't many uses for unsigned types of sizes  
> other than the full machine word. In all the other sizes, a positive  
> integer would be more useful.

Hm.. would it be useful to have a "guaranteed non-negative" integer type?   
Like array length.  Then the compiler could make that assumption, and do  
something like what I did as an optimization?

Subtracting from that type would result in a plain-old int.

-Steve


More information about the Digitalmars-d mailing list