OK, I'm puzzled, but maybe this warnings is a clue...?
Why do I get 9
here, but a friend gets 10
?
macro-puzzle.c
:
#include <stdio.h>
#define my_macro(a) (a) + (a)
int main() {
int x = 3;
x = my_macro(++x);
printf("x: %d\n", x);
return 0;
}
$ gcc macro-puzzle.c -o macro-puzzle && ./macro-puzzle
macro-puzzle.c:8:16: warning: multiple unsequenced modifications to 'x' [-Wunsequenced]
x = my_macro(++x);
^~
macro-puzzle.c:4:22: note: expanded from macro 'my_macro'
#define my_macro(a) (a) + (a)
^ ~
1 warning generated.
x: 9