转载自 https://gist.github.com/aras-p/6224951
原作者 Aras P 是 Unity 的 Graphics Architect
// 关键词替换,出了 bug 很难检测!#define struct union
#define if while
#define else
#define break
#define if(x)
#define double float
#define volatile // this one is cool
// 听说你喜欢数学#define M_PI 3.2f
#undef FLT_MIN #define FLT_MIN (-FLT_MAX)
#define floor ceil
#define isnan(x) false
// 随机大法好,大部分时间都“好好的”#define true ((__LINE__&15)!=15)
#define true ((rand()&15)!=15)
#define if(x) if ((x) && (rand() < RAND_MAX * 0.99))
// 字符串和内存操作,看上去不会出错的样子#define strcpy(a,b) memmove(a,b,strlen(b)+2)
#define strcpy(a,b) (((a & 0xFF) == (b & 0xFF)) ? strcpy(a+1,b) : strcpy(a, b))
#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)
#define sizeof(x) (sizeof(x)-1)
// 让我们搞搞线程和原子操作#define pthread_mutex_lock(m) 0
#define InterlockedAdd(x,y) (*x+=y)
// 你们没病吧?!#define __dcbt __dcbz // for PowerPC platforms
#define __dcbt __dcbf // for PowerPC platforms
#define __builtin_expect(a,b) b // for gcc
#define continue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break
// HLSL shaders 大杀器#define row_major column_major
#define nointerpolation
#define branch flatten
#define any all