Can I mimic a C header that redefines bool in C++?

You can hack it!

The library, call it fooLib, thinks it’s using some type bool which it has the prerogative to define. To the library, bool is just an identifier.

So, you can just force it to use another identifier instead:

#define bool fooLib_bool
#include "fooLib.h"
#undef bool
#undef true
#undef false

Now the compiler sees the offending line transformed to this:

typedef int fooLib_bool;

You’re stuck with the interface using type fooLib_bool = int instead of a real bool, but that’s impossible to work around, as the code might in fact rely on the properties of int, and library binary would have been compiled with such an assumption baked in.

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.