BufferedFile bug?

Janice Caron caron800 at googlemail.com
Thu Mar 6 05:37:23 PST 2008


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!!!???



More information about the Digitalmars-d mailing list