If you take Java’s primitive numeric types, plus boolean, and compare it to C++ equivalent types, is there any difference what concerns the operators, like precedence rules or what the bit-manipulation operators do? Or the effect of parenthesis?
Asked another way, if I took a Java expression and tried to compile and run it in C++, would it always compile and always give the same result?
For an expression like:
In Java, the evaluation order is well-defined (left to right). C++ does not specify whether
foo()orbar()is evaluated first.Stuff like:
is undefined in C++, but again well-defined in Java.
In C++, performing right-shifts on negative numbers is implementation-defined/undefined; whereas in Java it is well-defined.
Also, in C++, the operators
&,|and^are purely bitwise operators. In Java, they can be bitwise or logical operators, depending on the context.