Advertisement
Yunga

preprocessor_fun.h

Aug 19th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. // preprocessor_fun.h
  2. // https://gist.github.com/aras-p/6224951
  3. //
  4. // Just before switching jobs:
  5. // Add one of these.
  6. // Preferably into the same commit where you do a large merge.
  7. //
  8. // This started as a tweet with a joke of "C++ pro-tip: #define private public",
  9. // and then it quickly escalated into more and more evil suggestions.
  10. // I've tried to capture interesting suggestions here.
  11. //
  12. // Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
  13. // @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
  14. // @KarlHillesland, @rexguo, @tom_forsyth, @bkaradzic, @MikeNicolella,
  15. // @AlexWDunn and myself.
  16.  
  17.  
  18. // Easy keyword replacement. Too easy to detect I think!
  19. #define struct union
  20. #define if while
  21. #define else
  22. #define break
  23. #define if(x)
  24. #define double float
  25. #define volatile // this one is cool
  26.  
  27. // I heard you like math
  28. #define M_PI 3.2f
  29. #undef FLT_MIN #define FLT_MIN (-FLT_MAX)
  30. #define floor ceil
  31. #define isnan(x) false
  32.  
  33. // Randomness based; "works" most of the time.
  34. #define true ((__LINE__&15)!=15)
  35. #define true ((rand()&15)!=15)
  36. #define if(x) if ((x) && (rand() < RAND_MAX * 0.99))
  37.  
  38. // String/memory handling, probably can live undetected quite long!
  39. #define strcpy(a,b) memmove(a,b,strlen(b)+2)
  40. #define strcpy(a,b) (((a & 0xFF) == (b & 0xFF)) ? strcpy(a+1,b) : strcpy(a, b))
  41. #define memcpy(d,s,sz) do { for (int i=0;i<sz;i++) { ((char*)d)[i]=((char*)s)[i]; } ((char*)s)[ rand() % sz ] ^= 0xff; } while (0)
  42. #define sizeof(x) (sizeof(x)-1)
  43.  
  44. // Let's have some fun with threads & atomics.
  45. #define pthread_mutex_lock(m) 0
  46. #define InterlockedAdd(x,y) (*x+=y)
  47.  
  48. // What's wrong with you people?!
  49. #define __dcbt __dcbz // for PowerPC platforms
  50. #define __dcbt __dcbf // for PowerPC platforms
  51. #define __builtin_expect(a,b) b // for gcc
  52. #define continue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break
  53.  
  54. // Some for HLSL shaders:
  55. #define row_major column_major
  56. #define nointerpolation
  57. #define branch flatten
  58. #define any all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement