The Bizarre Hidden Powers of the Preprocessor? [closed]
- by ApprenticeHacker
The preprocessor in C and C++ deserves an entire essay on its own to explore its rich possibilities for obfuscation.
It is true that the C++ (and C) preprocessor can be used for a lot of powerful stuff. #ifdefs and #defines are often used to determine platforms, compilers and backends. Manipulating the code likewise. However, can anyone list some of the most powerful and bizarre things you can do with the preprocessor?
The most sinister use of the preprocessor I've found is this:
#ifndef DONE
#ifdef TWICE
// put stuff here to declare 3rd time around
void g(char* str);
#define DONE
#else // TWICE
#ifdef ONCE
// put stuff here to declare 2nd time around
void g(void* str);
#define TWICE
#else // ONCE
// put stuff here to declare 1st time around
void g(std::string str);
#define ONCE
#endif // ONCE
#endif // TWICE
#endif // DONE
This declares different things based on how many times the header is included.
Are there any other bizarre unknown powers of the C++ preprocessor?