Re: unexpected result



jaysome <jaysome@xxxxxxxxxxx> writes:
Jack Klein wrote:
[...]
ashu wrote:
[...]
include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}
[...]
No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.

There's always a result. But the result may not be as expected. Hence
unexpected behavior.

No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages