Notes IV
Sean Kelly
sean at f4.ca
Thu Jan 24 07:02:54 PST 2008
Oskar Linde wrote:
> bearophile wrote:
>
>> 16) Against C rules, in some situations I think it may be better if
>> some results are upcasted to ulong/long:
>> import std.stdio;
>> void main() {
>> uint a = 3_000_000_000;
>> uint b = 3_000_000_000;
>> writefln(a + b); // 1705032704
>>
>> int c = -1_600_000_000;
>> int d = -1_600_000_000;
>> writefln(c + d); // 1094967296
>> }
>> (The Ada language uses a different solution to avoid such class of
>> bugs, but it may be too much far from the style of C-like languages.
>> Delphi looks like a compromise).
>>
>
> On a similar topic, here are two of my favorite bugs:
>
>
> // Spot the bug # 1
> double randomDelta() {
> return (rand() % 3) - 1;
> }
>
> // spot the bug #2
> void fun(int[] arr) {
> long d = arr.length - 10;
> while (d > 0)
> arr[--d] = 0;
> }
>
I wonder if this will be resolved by the polysemous value change in 2.0,
whenever that happens?
Sean
More information about the Digitalmars-d
mailing list