disabling unary "-" for unsigned types
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 16 07:50:15 PST 2010
On Tue, 16 Feb 2010 10:36:04 -0500, Daniel Keep
<daniel.keep.lists at gmail.com> wrote:
>
> It's fun to note that one of the fixes the author proposes in the
> article was actually shown to itself be wrong... nearly two years later.
>
> Clearly, knowing that computers use two's complement fixed-width integer
> arithmetic is insufficient to write correct code. To believe otherwise
> is to believe that humans are infallible.
Yes, but in this case, the solution was incorrect for a small number of
inputs (arrays with length > 2^30).
For negation of unsigned values, the code is incorrect for all inputs
except for zero.
Appropriately, one will notice something is wrong sooner than a decade. I
would postulate they should know instantaneously because the compiler
should reject it :)
-Steve
More information about the Digitalmars-d
mailing list