c++ precompiler booleans
February 20, 2012
A short post to show you some of the possible precompiler if booleans you can write. I had to learn how to place several define requirements in one #if statement. Here you go:
#include <iostream>
#define M1
#define M2
using namespace std;
int main()
{
#ifdef M1
cout << “M1 defined!” << endl;
#endif
#ifdef M2
cout << “M2 defined!” << endl;
#endif
#ifndef M3
cout << “M3 not defined!” << endl;
#endif
#ifdef M4
cout << “M4 defined!” << endl;
#endif
#if defined(M1) && defined(M4)
cout << “M1 and M4 defined!” << endl;
#endif
#if defined M2 || defined M3
cout << “M2 or M3 defined!” << endl;
#endif
#if ! defined M3 && ! defined M4
cout << “neither M3 nor M4 defined!” << endl;
#endif
#if ! defined(M3) && defined M2
cout << “M3 not defined, M2 defined!” << endl;
#endif
return 0;
}
This code shows most options I know of. The output is (in case you are too lazy to check..):
M1 defined!
M2 defined!
M3 not defined!
M2 or M3 defined!
neither M3 nor M4 defined!
M3 not defined, M2 defined!
No comments yet
