0

I am getting two different answers in two different compiler .

#include<stdio.h>
#define square(a) a*a
main()
{
    int a=3;
    printf("%d ",square(a++));
    printf("%d ",square(a--));
}

In gcc 4.x versions output is 9 and 25 In newer gcc 12 and 20 are the outputs How are the newer compilers handling this compiler optimization? I want to know about the volatile in such compiler optimization issues.

Anjaneyulu
  • 434
  • 5
  • 21
  • And read the first answer of the duplicate. It seems what your are doing is undefined behavior because there is no clean usage of the macro there. – Kami Kaze Oct 17 '16 at 10:14
  • Read about 'sequence point's. The duplicate question should point you in the right direction to understand what's behind your problem. – Motun Oct 17 '16 at 11:12

0 Answers0