Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 900
kauray Avatar asked Jan 22 '16 16:01

kauray


People also ask

Is comma a sequence point?

A comma can only occur between two expressions – commas separate expressions – unlike the semicolon, which occurs at the end of a (non-block) statement – semicolons terminate statements. The comma operator has the lowest precedence of any C operator, and acts as a sequence point.

What is sequence point operation?

A sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.

What is sequence point in C++?

Pre-C++11 Definitions A sequence point is a point in the execution sequence where all side effects from the previous evaluations in the sequence are complete, and no side effects of the subsequent evaluations started.


1 Answers

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

like image 160
P.P Avatar answered Sep 28 '22 07:09

P.P