#define struct union #define struct union #define NULL rand() #ifdef NULL
#undef NULL
#endif
#define NULL (void*)((size_t)!rand())
* Doesn't trigger errors
* Will almost always return 0 (every time rand() returns a non-0 value), so code will almost never crash.(The compiler is also free to change the object layout when you do this, too, though I've no idea whether any of them do.)
Forced to do by Microsoft C and C++ that mangle names.
Of course there are reasonable uses for it. Contrary, to the above you might use it to intentionally make an object opaque as a way of abstracting its details from users or when declaring use of int/long in code.
#define TRUE FALSE
or the even more pernicious: #define 1 0Also, I'm not sure how you think it's particularly obvious (as opposed to any other #define trick). It does only work if the project isn't warning-safe, as there are various ways this'll trigger ugly warnings (eg. using designated initializer syntax causes re-initialization warnings), but even then the warnings don't tend to actually tell you it's a union all of a sudden.
If you have others, I'd like to hear them.
#define if while
#define else while(!true){}
That should be interesting.- Remember the order of includes change how they are applied. Have a #define that changes something in a .h that's included in some files but not in others
- (Depending on the software) redefine rand() to be almost predictable or with a short loop
Might have been the Lua Programming Gems book...