0

I was reading the Java Language Environment document at(https://www.oracle.com/java/technologies/introduction-to-java.html). In this paper, it is mentioned that

"Java technology puts a stake in the ground and specifies the sizes of its basic data types and the behavior of its arithmetic operators."

I know that in C/C++ the fundamental types are not strictly defined as in Java. But I do not understand the "behavior of arithmetic operators" part. Does the author mean that in C/C++ the behavior of arithmetic operators(on fundamental data types) is compiler/platform-dependent? If so, can anyone provide an example of how this above-mentioned behavior is different in Java when compared to C/C++ (or any other language)?

A-run
  • 470
  • 4
  • 13
  • 1
    https://stackoverflow.com/q/2397984/3890632 might be of interest. – khelwood Nov 14 '20 at 08:18
  • 1
    "Does the author mean that in C/C++ the behavior of arithmetic operators is compiler/platform-dependent?" The sentence you quoted says nothing about C/C++. – Sweeper Nov 14 '20 at 08:22
  • 1
    Many things about the shift operators are undefined, i.e. left up to the CPU architecture, in both C and C++, which BTW are two separate languages. – user207421 Nov 14 '20 at 09:07
  • @khelwood, thanks for the link. It was very useful. – A-run Nov 16 '20 at 05:03
  • @Sweeper, It does not say anything specifically about C or C++, but since Java was meant to be an OOP language that built on better features of C++ and also provided Architectural neutrality and portability, I assumed it was a fair comparison. – A-run Nov 16 '20 at 05:13
  • 1
    @user207421 In [this comment](https://stackoverflow.com/questions/64832034/#comment114625829_64832115) to a now-deleted answer, you claimed that integer overflow was undefined in Java. So I want to point you to [JLS §15.18.2](https://docs.oracle.com/javase/specs/jls/se15/html/jls-15.html#jls-15.18.2-400): “*If an integer addition overflows, then the result is the low-order bits of the mathematical sum as represented in some sufficiently large two's-complement format. If overflow occurs, then the sign of the result is not the same as the sign of the mathematical sum of the two operand values.*” – Holger Dec 15 '20 at 17:11

0 Answers0