Skip to content

Comment on X += x++parent

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

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.