Search code examples
cundefined-behaviorsequence-points

In a function call, why isn't comma a sequence point?


In the following code

int main(){  
    int a=3;  
    printf("%d %d %d",++a,a,a++);
    return 0;
}  

As specified, From C99 appendix C:,

The following are the sequence points described in 5.1.2.3:

  • The call to a function, after the arguments have been evaluated (6.5.2.2).
  • The end of the first operand of the following operators: logical AND && (6.5.13); logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17)

The order in which the arguments to a function are evaluated are undefined as specified by the C standard.

However, in the function call for printf, we have arguments that are separated by commas which classify as sequence points. So why does this statement correspond to unspecified behavior?


Solution

  • Because the comma in the function call is not the comma operator but a separator. So it doesn't introduce any sequence point(s).