Search code examples
clanguage-lawyerc89sequence-points

Is following statement valid in ANSI C? Is it valid at all?


During my preparation to exam on ANSI C I have encountered the following question -

Is following statement valid?
If not, please make required changes to make it valid.

The original statement is: test(i++,i++); it isn't valid because the behaviour is undefined according to K&R p202

The order of evaluation of arguments is unspecified

But can I change it to the following statement? test(i+=2, i+=3)?

The problem that I haven't seen such record in K&R or any other source. But XCode compile it and run without any warning.


Solution

  • Both are valid statements, i.e. legal C, and in both cases, the behavior is undefined.