Arithmetic in computers is different from the math you learned in school. It's 2's complement, and it's best to always keep that in mind when writing programs.

From http://embed.cs.utah.edu/ioc/

" Examples of undefined integer overflows we have reported:

    An SQLite bug
    Some problems in SafeInt
    GNU MPC
    PHP
    Firefox
    GCC
    PostgreSQL
    LLVM
    Python

We also reported bugs to BIND and OpenSSL. Most of the SPEC CPU 2006 benchmarks contain undefined overflows."

So how does D improve on C's model? If signed integers are required to wrap around in D (no undefined behaviour), you also prevent some otherwise possible optimizations (there is a reason it's still undefined behaviour in C).

Reply via email to