How big (in bits) is a Windows BOOL data type?
Microsoft defines the BOOL data type as:
BOOL Boolean variable (should be TRUE or FALSE).
This type is declared in WinDef.h as follows:
typedef int BOOL;
Which converts my question into:
How big (in bits) is an int data type?
Edit: In before K&R.
Pretend we're creating a typed programming language, and compiler. You have a type that represents something logically being True or False. If your compiler can also link to Windows DLLs, and you want to call an API that requires a BOOL data type, what data type from your language would you pass/return?
In order to interop with the Windows BOOL data type, you have to know how large a BOOL is. The question gets converted to how big an int is. But that's a C/C++ int, not the Integer data type in our pretend language.
So i need to either find, or create, a data-type that is the same size as an int.
Note: In my original question i'm not creating a compiler. i'm calling Windows from a language that isn't C/C++, so i need to find a data type that is the same size as what Windows expects.
bool The bool type takes one byte and stores a value of true (1) or false(0). The size of a bool is 1 true 1 1 1 false 0 0 0 Press any key to continue . . . int is the integer data type.
Because it's fast. A 32-bit processor typically works with 32-bit values. Working with smaller values involves longer instructions, or extra logic.
Internally, a Boolean variable is a 2-byte value holding –1 (for TRUE) or 0 (for FALSE). Any type of data can be assigned to Boolean variables. When assigning, non-0 values are converted to TRUE , and 0 values are converted to FALSE.
int is officially "an integral type that is larger than or equal to the size of type short int, and shorter than or equal to the size of type long." It can be any size, and is implementation specific.
It is 4 bytes (32 bits), on Microsoft's current compiler implementation (this is compiler specific, not platform specific). You can see this on the Fundamental Types (C++) page of MSDN (near the bottom).
Sizes of Fundamental Types
Type Size ======================= ========= int, unsigned int 4 bytes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With