Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:41:29+00:00 2026-06-16T04:41:29+00:00

Possible Duplicate: what is the size of an enum type data in C++? How

  • 0

Possible Duplicate:
what is the size of an enum type data in C++?

How is enum data type stored internally (I’d imagine as 8/16/32-bit int?) and can it be safely serialized or should I use something like quint8 to store the value? In other words is sizeof(MyEnum) guaranteed to be the same size on all platforms?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:41:30+00:00Added an answer on June 16, 2026 at 4:41 am

    In other words is sizeof(MyEnum) guaranteed to be the same size on all platforms?

    You can set an explicit type in C++11 (but not in earlier C++ incarnations):

    enum class Drug : char {
        Cocaine,
        Cannabis,
        Crack
    };
    

    or

    enum Sex : uint32_t {
        Male,
        Female,
        Other
    };
    

    Using class in front of enum by the way forces users of Drug to spell it Drug::Cocaine, for enumerations without the class in front of their declarations, the spelling is optional (both Sex::Male and Female are valid).

    Hacks for C++es prior 2011 include the following, which forces a minimal size:

    enum Frob {
        ...
        FORCE_DWORD          = 0x7fffffff
    };
    

    Seen in practice e.g. on ReactOS’ DirectX-SDK implementation.


    Standards references

    7.2 Enumeration Declarations [dcl.enum]

    […]

    §6: For an enumeration whose underlying type is not fixed, the underlying type is an integral type that can
    represent all the enumerator values defined in the enumeration. If no integral type can represent all the
    enumerator values, the enumeration is ill-formed. It is implementation-defined which integral type is used

    as the underlying type except that the underlying type shall not be larger than int unless the value of an
    enumerator cannot fit in an int or unsigned int. If the enumerator-list is empty, the underlying type is
    as if the enumeration had a single enumerator with value 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Size of character ('a') in C/C++ Can someone explain why in C
Possible Duplicate: Get total size of folders with find & du I can use
Possible Duplicate: size of int, long, etc Does the size of an int depend
Possible Duplicate: How can I get the size of an array from a pointer
Possible Duplicate: Size of character ('a') in C/C++ OS: linuxmint 32-bit Compiler: gcc &
Possible Duplicate: Size of character ('a') in C/C++ The following program #include <stdio.h> int
Possible Duplicate: Auto-size dynamic text to fill fixed size container How can I get
Possible Duplicate: Can someone explain this template code that gives me the size of
Possible Duplicate: Size of struct with a single element Given any type A and
Possible Duplicate: Does the size of an int depend on the compiler and/or processor?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.