The following code yields different outputs on different compilers;
#include <stdio.h>
void fun(int x, int y, int z) /* function definition */
{
printf("%d %d %d n", x, y, z); /* 6 6 6 */
}
int main()
{
int a = 3;
fun(++a, ++a, ++a); /* function call */
return 0;
}
So far the code has yielded the outputs – 6 6 6, 6 5 4, 4 5 6 on different compilers.
Does this behaviour have anything to do with order of evaluation of function arguments or could it be due to calling convention (cdecl)? Will changing to a convention (if that’s possible) change the output of the aforementioned code in any way?
The code snippet is from a book which was trying to introduce calling conventions in C. I’m new to C so please keep it as simple as possible or provide context.