BufferedFile bug?
Lionello Lunesu
lionello at lunesu.remove.com
Thu Mar 6 18:04:23 PST 2008
"Janice Caron" <caron800 at googlemail.com> wrote in message
news:mailman.118.1204810684.2351.digitalmars-d at puremagic.com...
> On 06/03/2008, Oskar Linde <oskar.lindeREM at ovegmail.com> wrote:
>> The problem is that:
>>
>> uint x = 1;
>> long y = -x;
>>
>> yields y == 4294967295
>
> (I changed the variable names because lowercase L looks like one to me).
>
> Huh?
>
> Why doesn't y equal minus one?
>
> I wouldn't call that a bug in BufferedStream.flush(), I'd call it a
> bug in D's arithmetic generally.
>
> The way I see it, there are two possible fixes:
>
> (1) Disallow unary minus completely for all unsigned types. Thus
>
> uint x = 1;
> long y = -x; /*ERROR*/
>
> forcing the user to explicitly write
>
> long y = -cast(int)x;
>
> or
>
> long y = -cast(long)x;
>
> either of which should be OK, or
>
> (2), when unary minus is applied to an unsigned type, promote ubyte to
> short, ushort to int, uint to long, ulong to cent (...best make that
> one illegal for now). That would mean
>
> uint x = 1;
> long y = -x; /* OK */
>
> but
>
> uint x = 1;
> int y = -x; /* Error */
>
> Either would work, but the status quo /can't/ be right!!!???
Andrei Alexandrescu posted a .pdf a while back with a graph containing all
types and directed edges for all allowed implicit promotions.. I think he
has it on his site, but I can't seem to access it (erdani.org) from China.
Has he been politcally active lately?? : )
L.
More information about the Digitalmars-d
mailing list