disabling unary "-" for unsigned types

dsimcha dsimcha at yahoo.com
Tue Feb 16 09:39:30 PST 2010


== Quote from Robert Jacques (sandford at jhu.edu)'s article
> Actually, this bug is more common than that; overflow can happen on arrays
> of length uint.max/2 and that's to say nothing of using 64-bit code. Also,
> the std.algorithm binary search routines use a different algorithm that
> appears to be safe to use. (Though they won't compile in 64-bit mode due
> to a minor bug)

Well, really you should be using size_t instead of int (which I do) to deal with
the 64-bit issue.  I guess there is a good point here in that sense.  However,
assuming size_t.sizeof == (void*).sizeof and half your address space is reserved
for kernel use, the only way this bug could bite you is on absurdly large arrays
of bytes, where binary search is almost always the wrong algorithm anyhow.



More information about the Digitalmars-d mailing list