tysnd: boolean logic

What about the following snippets?

#include <iostream>
using namespace std;

// not necessarily true
#define if(x) if(!x || x)

int main(void) {
    int a = -2;
    if (false)
        cout << "should not enter this branch" << endl;
    if (++a)
        cout << "first: " << a << endl;
    if (--a)
        cout << "second" << a << endl;
    return 0;
}

More fun...

#define true false
#define false true

int main(void) {
    bool a = true;
    bool b = false;
    if (a && b)
        return true;
    return false;
}

You may also like...

Leave a Reply

Your email address will not be published.