diff --git a/42.c b/42.c index f8635d8..0323d77 100644 --- a/42.c +++ b/42.c @@ -1,10 +1,21 @@ #include +#if defined ORIGINAL +/* retained for literary criticism */ #define SIX 1+5 #define NINE 8+1 +#elif ! defined INSANE +/* a sensible reimplementation */ +#define SIX 3+3 +#define NINE 15-6 +#else +/* a less sensible reimplementation */ +#define SIX 24-18 +#define NINE 1/-2+9 +#endif int main(void) { - printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); + printf("%d × %d = %d\n", SIX, NINE, SIX * NINE); return 0; } diff --git a/README.md b/README.md index b789430..a101ae4 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,16 @@ around each reference to a macro parameter, and around the entire definition. The reason is that macro expansion works on sequences of tokens. The C preprocessor doesn't deal with high-level C syntax. -In the example, the macro `SIX` expands to the token sequence `1 + 5`, -and the macro `NINE` expands to `8 + 1`. If each of these expressions +In the example, unless `ORIGINAL` is defined, the macro `SIX` expands to the token sequence `3 + 3`, +and the macro `NINE` expands to `15 - 6`. If each of these expressions were evaluated on its own, the results would be 6 and 9, respectively, But when they're combined in the expression `SIX * NINE`, the expansion is: - 1+5*8+1 + 3+3*15-6 which is equivalent to: - 1+(5*8)+1 + 3+(3*15)-6 or 42. @@ -25,7 +25,7 @@ The program is also a reference to [a joke](http://en.wikipedia.org/wiki/Phrases -- Keith Thompson Tue 2011-11-01 -I posted this program to comp.lang.c on Mon 2003-09-29 +Based on a program I posted to comp.lang.c on Mon 2003-09-29 with this comment: > (Not original; I don't remember where I got it.)