In an old Windows XPSP3 VM with VS2005 installed the defaults were 4 bytes for enum and int. The C++ bool type was 1 byte. The Win32 BOOL is 4 bytes.
Has the size of an enum changed over various visual studio versions
The C++ standard says that an enum can be any size (byte, word, etc) as long as it is large enough to hold the data. In visual studio 2019, it looks like the size of an enum defaults to 4 bytes.
I'm trying to communicate with a program written in visual studio 2003 running on and windows XP computer. Does anyone know if the same default existed in visual studio 2003? Or has the default size changed.
Same question for int and bool, although I believe them both to be 4 bytes.
Sign in to comment
Sort by: Most helpful
std::cout << sizeof(bool); std::cout << sizeof(int);
If you try to run this code, you'll see that it outputs 1 and 4, so bool and int don't have the same number of bytes.
In the C++ language standard, its size is fixed when dealing with boolean values, and the minimum is 1 byte. The exact implementation may vary by compiler and operating system.
If the answer is the right solution, please click "Accept Answer" and upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.