Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep BOOL instead of bool

Tags:

c++

boolean

I know, that bool is used in C++, while BOOL is a Microsoft specific type that is defined as an int.

My code is using BOOL as it was made for Windows to start with, but I'm trying to keep things the same way without changing my code from BOOL to bool, when I'm going port it to Mac.

Could something like this work?

    typedef int8_t _Bool;         
    typedef _Bool (BOOL);
    static const BOOL False = 0;
    static const BOOL True = 1;

If yes, is there a better way and why?
If not, then why and what should I do instead?

like image 902
user1417815 Avatar asked Dec 19 '25 11:12

user1417815


2 Answers

I don't see why a good IDE couldn't make a global change from BOOL to bool. I'd prefer having greater portability. I wouldn't like the typedefs, because it'd be harder to read.

like image 50
duffymo Avatar answered Dec 22 '25 02:12

duffymo


The biggest problem that I see with rolling your own bool is that template specifications that recognize bool will not recognize BOOL, going the default route. Specifically, vector<bool> uses a different code base to save space by packing bits in a representation of the vector; using vector<BOOL> will result in a representation that is roughly eight times larger.

like image 34
Sergey Kalinichenko Avatar answered Dec 22 '25 02:12

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!