4 ms·
Things to commit before you quit your job
- benburleson 13y agoNot a good time to submit links to github, I guess.
- _ak 13y ago"Things to commit before you quit your job if you want to get sued your ass off by your former employer."
- octo_t 13y ago#define if(x) if ((x) && (rand() < RAND_MAX * 0.99)) its pretty awesome. I'm a fan of: #define == =
- zeckalpha 13y agoThis calls for hygienic macros.
- zalzane 13y agooh man I love these. Here's an old gem I came across a few years back: https://gist.github.com/bsamuels453/5819204 https://gist.github.com/bsamuels453/5819204 This is a bitch to detect if you have a huge project. The #ifndef _DEBUG is like frosting on the cake. Templates are truly C++'s greatest 'gift'
- aras_p 13y agoAuthor of the linked gist here. Some backstory: someone tweeted a "C++ protip: #define private public" joke. I replied with the excellent "#define struct union - saves memory!" that I saw somewhere (all valid C programs will still compile, though not necessarily C++ ones). And then twitter conversation went to more and more evil suggestions. I just captured them in the gist. My favorites are "#define strcpy(a,b) memmove(a,b,strlen(b)+2)" - which can go unnoticed in a long, long time; and "#define InterlockedAdd(x,y) (*x+=y)" - which would be total hell for someone to debug, as if lockless programming wouldn't be hard enough already.
- markjdb 13y ago> all valid C programs will still compile, though not necessarily C++ ones I don't think that's true: struct foo { int a; int b; }; char arr[sizeof(struct foo) == sizeof(int) ? -1 : 1];
- aras_p 13y agoOk, proved me wrong! The ones that check for struct sizes at compile time (like in your example) will fail since sizes will be different now.