In general, reading and writing to a variable in the same statement can lead to problems. It's not a problem here, but that's not obvious at a glance. For example, that code has undefined behaviour in C. My compiler happens to get it "wrong":
$ cat a.c
#include <stdio.h>
int main() {
int i = 0;
printf("%d %d %d\n", i++, i++, i++);
return 0;
}
$ gcc -Wall -o a a.c && a
a.c: In function ‘main’:
a.c:5: warning: operation on ‘i’ may be undefined
a.c:5: warning: operation on ‘i’ may be undefined
2 1 0
It's simpler just to avoid the issue.
|