cwick cwick - 24 days ago 7
C Question

What is the point of saying "#define FOO FOO" in C?

I came across some C code where the author uses the following idiom all over the place:

typedef __int32 FOO_INT32;
#define FOO_INT32 FOO_INT32


What is the point of doing this? Shouldn't the typedef be enough? It is a workaround for some wonky C compilers out there?

Answer

With the #define instruction, you'll then be able to test if the typedef has been done somewhere else in the code using :

#ifdef FOO_INT32
FOO_INT32 myfoo;
#else
int myfoo;
#endif