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 6148215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:14:31+00:00 2026-05-23T19:14:31+00:00

I am working with a custom enumerated type in C++, but it does not

  • 0

I am working with a custom enumerated type in C++, but it does not have many values. I want to try to reduce the size that they take up, and I’ve heard that enum types are always integers by default. I then came across the MSDN entry on C++ enumerations, and found the following syntax very interesting:

enum [: type] {enum-list};

Sure enough, it compiled with what I wanted (VS2008) when I did the following:

enum plane : unsigned char { xy, xz, yz };

Now, you can see from my enumeration constants that I don’t need much in terms of space – an unsigned char type would be perfect for my uses.

However, I have to say, I’ve never seen this form used anywhere else on the internet – most don’t even seem aware of it. I’m trying to make this code cross-platform (and possibly for use on embedded systems), so it left me wondering… Is this proper C++ syntax, or only supported by the MSVC compiler?

Edit: It seems that this feature is now part of C++11 and above, and is called scoped enumerations.

  • 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-05-23T19:14:32+00:00Added an answer on May 23, 2026 at 7:14 pm

    As 0A0D’s said, the notation you’re using is non-Standard in C++03, but has been adopted by C++11 under the term “scoped enums”.

    If that’s not soon enough for you, then you can consider explicitly specifying the bit field width used for the enum fields in the size-critical structures in which they’re embedded. This approach is ugly – I mention if for completeness; if it was a good solution the notation above wouldn’t be being adopted for C++11. One problem is that you rely on an optional compiler warning to detect too-small bit-fields to hold the possible values, and may have to manually review them as the enumeration values change.

    For example:

    enum E
    {
        A, B, C
    };
    
    struct X
    {
        E e1 : 2;
        E e2 : 2;
        E e3 : 2;
        E e4 : 2;
    };
    

    Note: the enum may occupy more bits than requested – on GCC 4.5.2 with no explicit compiler options, sizeof(X) above is still 4….

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

Sidebar

Related Questions

I have a working custom UserNamePasswordValidator that calls into my Oracle DB. This class
I am working on a custom avatar system for a project, but I have
I'm working on a custom user control that essentially displays a name value pair
I am working on a custom .emacs file that I will be able to
I have a working custom login realm (provided by a third-party) for Glassfish 3.1.1.
I have a working custom search suggestions class (via http://developer.android.com/guide/topics/search/adding-custom-suggestions.html ). It currently returns
I'm working on custom control that I can use for interactions within my app
I'm having trouble figuring out why the following is not working: My custom JS
I am working on a custom list view. I want to show a CheckBox
Inside phpMyAdmin, I am working with custom meta fields in WordPress. Say I have

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.