64 KiB should be enough for everyone

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 21 18:07:15 PST 2014


On 11/21/2014 1:33 PM, Marco Leise wrote:
> As someone using unsigned types all the time, all I need to
> keep in mind are two rules:
>
> 1) Overflow:
>
>    uint number;
>>    number = 10 * number + ch - '0';
>
>    It is handled with:
>    if (number > uint.max / 10)
>    if (number > uint.max - (ch - '0'))

You're better off with core.checkedint here, as not only is it correct, but 
(eventually) it will enable the compiler to optimize it to simply checking the 
carry flag.



More information about the Digitalmars-d mailing list