Hacker News new | past | comments | ask | show | jobs | submit login

Java throws exceptions on overflow (and underflow), which presumably interferes with that, e.g.:

  int A = 3000000000;
  int B = 3000000000;
  int C = -3000000000;
  int D;
  D = A + B + C;
Depending on order of evaluation, this either throws an overflow exception or assigns the number 3 billion to D. There is a hard rule in the spec that defines what must happen here. In C or C++ there are no such exceptions, so the compiler can (and does) transform arithmetic expressions where it's advantageous. (this is obviously a trivial example which will compile down to a constant anyway)



But http://java.sun.com/docs/books/jls/second_edition/html/types... says

> The built-in integer operators do not indicate overflow or underflow in any way. The only numeric operators that can throw an exception are the integer divide operator / and the integer remainder operator %, which throw an ArithmeticException if the right-hand operand is zero.

Maybe it's true that subexpressions can't be reordered for other reasons, but offhand I can't find that restriction.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: