4 ms·
In a global header long time ago, a friend of mine (and big "C" lover) did this to his best buddy once (a C++ and especially boost lover): #define class struct
by malkia 16y ago
In a global header long time ago, a friend of mine (and big "C" lover) did this to his best buddy once (a C++ and especially boost lover):
#define class struct
#define private public
#define protected public
- jmatt 16y agocontinued "fun" (read dangerous) redefines: #define true false #define false true #define true 0 #define false !true #define if while #define continue break :)
- chaosgame 16y ago#define struct union
- moultano 16y agoThat is by far the evilest of the bunch. }:-D
- shasta 16y ago#define true false #define false true Did you know that if you do both of those, they cancel each other out? True story.
- troels 16y agoMy head hurts. Explanation, please?
- malkia 16y agoDunno about explanation, but experiment shows it to work at least with two preprocessors - Microsoft's and GCC: First make a file a.c that has in it: #define true false #define false true int A = true; int B = false; then from the command line, do (with the Microsoft compiler): D:\>cl -E a.c int A = true; int B = false; Now with gcc (I'm using cygwin's gcc): D:\>sh -c "gcc -E a.c" int A = true; int B = false; I've stripped the other stuff.
- shasta 16y agoThere's a rule in the preprocessor to prevent infinite recursion: only replace each symbol once. The first time it encounters 'true', it's replaced with 'false'. The first time it encounters 'false, it's replace with 'true'. It's already seen 'true', so it throws up its hands. The consequence of this rule is that cycles of #defines don't do anything. Edit: Well, that's only true if there aren't other symbols introduced during expansion. Here's a counterexample that prints 3: #include <stdio.h> int x = 1; #define x 1 + y #define y 1 + x int main(int argc, char *argv[]) { printf("%d\n",x); return 0; }
- troels 16y agoAh .. Makes sense. Thanks.
- deleted 16y ago[deleted]
- deleted 16y ago[deleted]
- VeXocide 16y ago#define TRUE random()%2
- rjurney 16y agoYou are truly devious
- aphyr 16y agoThis gets even more fun in languages which allow unicode names. Did you know there are dozens of identical-looking ways to spell "true"?
- angusgr 16y agoI have an innate fascinated horror of the C preprocessor already, but this really drives home exactly how horrible it can be! (While being quite funny, mind you!)
- rbanffy 16y agoI once opened Squeak and said "True := False" The image halted immediately.