Groups
Groups
Sign in
Groups
Groups
fosscafe
Conversations
Labels
About
Send feedback
Help
what is the smallest undefined C program ?
15 views
Skip to first unread message
Saifi
unread,
Jan 1, 2018, 6:35:11 AM
1/1/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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