The compilers might be more helpful, too, by displaying hints or even warnings when the clever code is used. This would not forbid it but would encourage for universally cleaner code.
$ cat foo.c
#include <stdio.h>
int main(int ac, char av)
{
int x = 3;
x = x + x++;
printf("x = %d\n", x);
return 0;
}
$ make foo CFLAGS=-Wall
cc -Wall foo.c -o foo
foo.c: In function ‘main’:
foo.c:5: warning: operation on ‘x’ may be undefined
$ ./foo
x = 7
Comments
The compilers might be more helpful, too, by displaying hints or even warnings when the clever code is used. This would not forbid it but would encourage for universally cleaner code.
Some compilers do that actually, and there are also code inspection tools that will give you warnings about such constructs.
$ cat foo.c #include <stdio.h> int main(int ac, char av) { int x = 3; x = x + x++; printf("x = %d\n", x); return 0; } $ make foo CFLAGS=-Wall cc -Wall foo.c -o foo foo.c: In function ‘main’: foo.c:5: warning: operation on ‘x’ may be undefined $ ./foo x = 7