'int' is enough for 'length' to migrate code from x86 to x64
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Fri Nov 21 11:41:55 PST 2014
On Fri, Nov 21, 2014 at 10:57:44AM -0800, Walter Bright via Digitalmars-d wrote:
> On 11/21/2014 10:05 AM, ketmar via Digitalmars-d wrote:
> >why do you believe that i'm not aware of overflows and don't checking
> >for that? i'm used to think about overflows and do overflow checking
> >in production code since my Z80 days. and i don't believe that
> >"infrequent bug" is better than "frequent bug". both are equally bad.
>
>
> Having coded with 16 bit computers for decades, one gets used to
> thinking about and dealing with overflows :-)
I used to write 8-bit assembly code on the 6502 (yeah I'm so dating
myself), where overflows and underflows happen ALL THE TIME. :-) In
fact, they happen so much, that I learned to embrace modulo arithmetic
instead of fearing it. I would take advantage of value wrapping to shave
off a few cycles here and a few cycles there -- they do add up, given
that the CPU only ran at a meager 1MHz, so every little bit counts.
Then in the 16-bit days, I wrote a sliding-window buffer using a 64kB
buffer where the wraparound of the 16-bit index variable was a feature
rather than a bug. :-) Basically, once it reaches within a certain
distance from the end of the window, the next 32kB block of data was
paged in from disk into the other half of the buffer, so as long as the
operation didn't span more than 32kB each time, you can just increment
the 16-bit index without needing to check for the end of the buffer --
it'd automatically wrap around to the beginning where the new 32kB block
has been loaded once you go past the end. A truly circular buffer! :-P
T
--
That's not a bug; that's a feature!
More information about the Digitalmars-d
mailing list