...
Non-compliant Code Example 3
The order of evaluation of arguments to a function is undefined.
Code Block |
---|
func(i++, i++);
|
Compliant Solution
The following solution is appropiate when the programmer intends for both arguments to func() to be equivalent:
Code Block |
---|
i++;
func(i, i);
|
The following solution is appropiate when the programmer intends for the second argument to be one greater than the first:
Code Block |
---|
j = i;
j++;
func(i, j);
|
Consequences
References
- ISO/IEC 9899-1999 Section 5.1.2.3 Program execution
- ISO/IEC 9899-1999 Section 6.5 Expressions
- ISO/IEC 9899-1999 Annex C Sequence points
- comp.lang.c FAQ list - Questions 3.1, 3.2, 3.3, 3.3b, 3.7, 3.8, 3.9, 3.10a, 3.10b, 3.11