/* Copyright (C) 2008-2010 Nick Bowler * * License WTFPL2: Do What The Fuck You Want To Public License, version 2. * This is free software: you are free to do what the fuck you want to. * There is NO WARRANTY, to the extent permitted by law. * * This is, to the best of my knowledge, a strictly conforming ANSI C * (C89) program which is not a C++ program. This proves by counter- * example that C++ is not a superset of C. * * Some of the "techniques" used in this file are stupid legacy features. * Please don't take this as an example of a well-written C program. * * The output of this program should be: * The old answer was 42, but the new answer is 54. * * There are more than 10 different things wrong with this program if you * consider it as C++. Can you spot them all? This is not valid C99 for * a few of these reasons. For now, it is pointless to update this to * C99 -- there are just too many obvious incompatibilities. */ #include #include #define and 42 #define or 54 static struct baz { struct foo { enum { ANSWER1 = and, ANSWER2 = or, ANSWER3 = -ANSWER1 } val; } foo; }; const int foo; typedef int baz(); baz main; int main(argc, argv) int argc; char **argv; { struct foo foo = { 0 }; int *new; if (argc >= foo.val) { return main(bar(), argv); } goto assign; { int old = 0; assign: old = -argc; new = malloc(sizeof 'x'); if (!new) { perror("malloc"); return EXIT_FAILURE; } *new = ANSWER2; printf("The old answer was %d, but the new answer is %d.\n", old, *new); free(new); } return 0; } bar() { return (enum{X = ANSWER3})-X//**/-1 ; }