what is the smallest undefined C program ?

15 views
Skip to first unread message

Saifi

unread,
Jan 1, 2018, 6:35:11 AM1/1/18
to foss...@googlegroups.com
attribution: Grigor Rosu.

----8<-----

#include <stdio.h>

int main() {

int x = 0;

return (x = 1) + (x = 2);
}

----8<-----

assuming you saved the above C code in a file named undef.c

$ gcc undef.c
$ ./a.out
$ echo $?
4

$ clang undef.c
undef.c:7:15: warning: multiple unsequenced modifications to 'x' [-Wunsequenced]
return (x = 1) + (x = 2);
^ ~
1 warning generated.
$ ./a.out
$ echo $?
3

--

with gcc, the value returned in 4.
with clang, the value returned is 3.


warm regards
Saifi.
Reply all
Reply to author
Forward
0 new messages