17 Sep 2004 (updated 17 Sep 2004 at 17:34 UTC) »
#ifndef INITIALIZED
#define INITIALIZED
#ifndef N
#define N 11
#endif
#define A ((N)&1)
#define B ((N)>>1&1)
#define C ((N)>>2&1)
#define D ((N)>>3&1)
int
main(void)
{
printf("fact(%d) = %d", N,
#include __FILE__
);
}
#else /* INITIALIZED */
(8*D + 4*C + 2*B + A)
#if A
#define A 0
#else
#define A 1
#if B
#define B 0
#else
#define B 1
#if C
#define C 0
#else
#define C 1
#if D
#define D 0
#endif
#endif
#endif
#endif
#if A || B || C || D
*
#include __FILE__
#endif
#endif
Credit where credit is due: the idea comes from the IOCCC entry that does Towers of Hanoi with the preprocessor.
For our next example, we'll show how you can generate code for a 256-point FFT with the preprocessor.
(to be continued)
FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!