29 January 2011

Order of argument evaluation in C, left-to-right or right-to-left?

Suppose you have written the below codes:

#include
 
  int global_a = 10;
 
  int increase(void)
  {
       return global_a += 10;
  }

 int main(void)
 {
      printf("%d,%d\n", increase(), global_a);
 }
 
And you compile it, what output would you expect? "20,10"? or "20,20"? 
 
I was thinking "surely it is 20,20!". But this post says both are right! Wow.....
Note: the original poster was actually comparing GCC to TCC (Tiny C Compiler).

regards,
 
Mulyadi.

No comments:

How to execute multiple commands directly as ssh argument?

 Perhaps sometimes you need to do this: ssh user@10.1.2.3 ls It is easy understand the above: run ls after getting into 10.1.2.3 via ssh. Pi...