Has the size of an enum changed over various visual studio versions

james bloomscheff 1 Reputation point
2022-11-07T21:28:59.627+00:00

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.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 40,286 Reputation points
    2022-11-07T22:01:45.78+00:00

    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.

    0 comments No comments

  2. YujianYao-MSFT 4,271 Reputation points Microsoft Vendor
    2023-03-16T07:29:12.4+00:00

    Hi james bloomscheff,

        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.

    Best regards,

    Elya


    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.

    0 comments No comments