Alan wrote:
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:41***************@gascad.at... Sprite wrote:
I write the following code
int x1 = 5;
std::cout<<x1--<<" "<<x1--<<" "<<x1;
and got the result
4 5 3
in VS2003
who can explain that, THX
You encountered 'undefined behaviour'
You modify the same variable twice without an intermediate
sequence point.
What do you mean by "without an intermediate sequence point",
please?
As said: Please search the groups archive at google.
In short: C++ devides the execution of a program in sequences.
Each sequence is terminated with a sequence point (roughly:
every ';', every function call, ... denote a sequence point).
If you modify the same variable twice in a sequence, you have
undefined behaviour, as the compiler can do the actual assignment
anywhere within that sequence. There is only 1 restriction for the
compiler: it has to happen before the sequence point is reached. But
when exactly, is left to the compiler.
--
Karl Heinz Buchegger
kb******@gascad.at