I've written a C program and then compiled and run it in MS Visual Studio and then using GCC. The program makes a few simple math calculations. But the outputs/results I get from both are different. The program is based on macros.
Do these programming environments have a different way of handling macros? If so, what is the difference?
EDIT: Sorry, here's the code.
#include <stdio.h>
#define mac(a,b) a*a + b*b - 2*a*b
int func(int a, int b) {
return (a*a + b*b - 2*a*b);
}
main() {
int f, g, i, j, x, y;
printf("Please enter two integers\n");
scanf("%d%d", &f, &g);
printf("f = %d\tg = %d\n", f, g);
i = f;
j = g;
x = func(i, j);
y = mac(i, j);
printf("x = %d\ty = %d\n", x, y);
x = func(++i, ++j);
i = f;
j = g;
y = mac(++i, ++j);
printf("i = %d\tj = %d\n", i, j);
printf("x = %d\ty = %d\n", x, y);
}
Here's the output using VS:
f = 7 g = 8
x = 1 y = 1
i = 10 j = 11
x = 1 y = 1
And using GCC:
f = 7 g = 8
x = 1 y = 1
i = 10 j = 11
x = 1 y = -39
The difference is the last y value. So I'm wondering if the different compilers go through the macro's process differently?