]> git.draconx.ca Git - scripts.git/blob - c-is-not-cxx.c
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / c-is-not-cxx.c
1 /* Copyright (C) 2008-2010 Nick Bowler
2  *
3  * License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4  * This is free software: you are free to do what the fuck you want to.
5  * There is NO WARRANTY, to the extent permitted by law.
6  *
7  * This is, to the best of my knowledge, a strictly conforming ANSI C
8  * (C89) program which is not a C++ program.  This proves by counter-
9  * example that C++ is not a superset of C.
10  *
11  * Some of the "techniques" used in this file are stupid legacy features.
12  * Please don't take this as an example of a well-written C program.
13  *
14  * The output of this program should be:
15  *   The old answer was 42, but the new answer is 54.
16  *
17  * There are more than 10 different things wrong with this program if you
18  * consider it as C++.  Can you spot them all?  This is not valid C99 for
19  * a few of these reasons.  For now, it is pointless to update this to
20  * C99 -- there are just too many obvious incompatibilities.
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25
26 #define and 42
27 #define or  54
28
29 static struct baz {
30         struct foo {
31                 enum {
32                         ANSWER1 = and,
33                         ANSWER2 = or,
34                         ANSWER3 = -ANSWER1
35                 } val;
36         } foo;
37 };
38
39 const int foo;
40 typedef int baz();
41 baz main;
42
43 int main(argc, argv)
44         int    argc;
45         char **argv;
46 {
47         struct foo foo = { 0 };
48         int *new;
49
50         if (argc >= foo.val) {
51                 return main(bar(), argv);
52         }
53
54         goto assign;
55         {
56                 int old = 0;
57         assign:
58                 old = -argc;
59
60                 new = malloc(sizeof 'x');
61                 if (!new) {
62                         perror("malloc");
63                         return EXIT_FAILURE;
64                 }
65
66                 *new = ANSWER2;
67                 printf("The old answer was %d, but the new answer is %d.\n",
68                                                                   old, *new);
69                 free(new);
70         }
71
72         return 0;
73 }
74
75 bar()
76 {
77         return (enum{X = ANSWER3})-X//**/-1
78                 ;
79 }