8 comments

[ 3.4 ms ] story [ 32.5 ms ] thread
Not a good time to submit links to github, I guess.
"Things to commit before you quit your job if you want to get sued your ass off by your former employer."

  #define if(x) if ((x) && (rand() < RAND_MAX * 0.99))
its pretty awesome. I'm a fan of:

  #define == =
This calls for hygienic macros.
oh man I love these.

Here's an old gem I came across a few years back:

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'

Author 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.

> 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];
Ok, 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.