M
M
MorganStanley2016-07-21 14:58:43
C++ / C#
MorganStanley, 2016-07-21 14:58:43

Wrong calculation?

I can't understand why the constructions produce different results, depending on the compiler. Checked on JS and Java, give the same correct result (as I think):
JS:
kiss_5kb.1469101944.png
Java:
kiss_34kb.1469102282.png
Link to Java example: goo.gl/HD223t
And here are the results of C ++:
MSVCC 2015
kiss_6kb.1469102108.png
cpp.sh (gcc 4.9.2)
kiss_17kb.1469102183.png
WTF?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2016-07-21
@MorganStanley

For C++, this construct violates the language standard and leads to undefined behavior. You can't write like that in C++.

J
jcmvbkbc, 2016-07-21
@jcmvbkbc

give the same correct result.

equally correct result for java, because the order of evaluation of the value of expressions in java is strictly defined for any expression, see https://docs.oracle.com/javase/specs/jls/se7/html/...
C++ -- this is a different language, you can write an expression like yours in it, the meaning of which is not defined by the standard and may vary depending on the compiler, optimization options and the phase of the moon. See https://ru.wikipedia.org/wiki/%D0%A2%D0%BE%D1%87%D...

S
sitev_ru, 2016-07-21
@sitev_ru

Even girls write about this: alenacpp.blogspot.ru/2005/11/sequence-points.html ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question