What tasks, features, executions vary with compiler? I know this code is compiler-dependent-
#include <stdio.h>
#define PRODUCT(x)(x*x)
int main()
{
int i=3,j,k;
j=PRODUCT(i++);
k=PRODUCT(++i);
printf("\n%d %d",j,k);
}
Following gives garbage in some, while fixed values in others-
#include <stdio.h>
int main()
{
int i=5,j=10;
printf("%d,%d");
}
So order of execution vary with compilers.
Are such ambiguous programs eligible to be asked in exams?
If you want the full list, you’ll need to look to the standard document. In the C standard there are two types of ‘compiler-dependent’ issues defined:
-1 >> 1may vary between compilers, but the compiler has to be consistent about it.You also need to watch out for constraint violations. Often the standard specifies things like “[
main] shall be defined with a return type ofint[…]” (§5.1.2.2.1/1). This is equivalent to, “Ifmainis declared with a return type other thanint, the program’s behavior is undefined.” (see §4.2, where the standard explicitly endorses this interpretation)You should not be asked these questions on an exam; if you are, you should simply state that the behavior of the program is undefined (or implementation-defined). Note that some implementation-defined behavior has limits – eg, the value of
sizeof(int)is implementation defined, but you know thatsizeof(int) >= sizeof(short) && sizeof(int) <= sizeof(long)– so just having any implementation-defined behavior doesn’t mean you can’t say anything about what the program does.