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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:11:33+00:00 2026-06-06T14:11:33+00:00

we use VS 2008 there is a big enum, which is populated by many

  • 0

we use VS 2008

there is a big enum, which is populated by many developers

this enum has a type __int64 (a Microsoft extension), and I want to make compiler complain about non unique values in enum.

if it was a usual enum I would do like this:

enum E1
{
    E11 = 0x01F00,
    E12 = 0x01F00,
    E13
};
#pragma warning(push)
#pragma warning(error: 4061)
#pragma warning(error: 4062)
void F(E1 e1)
{
    switch (e1)
    {
    case E11:
    case E12:
    case E13:
        return;
    }
}
#pragma warning(pop)

and the function F would have an error, if E1 has 2 same values

and it would have another error, if a developer forgot to add a new value to switch

but my enum has type __int64 (or long long)

and when I try do the same switch for E1 e1 it truncates values and complains on values, wich difference is either 0x100000000, or 0x200000000 ….

if I cast e1 to __int64, the compiler does not complain, if a developer forgets to add a new value to the switch (so the whole check function becomes useless)

the question: does someone know what I can do about it? or maybe VS 2008 (or C++) has another instrument to ensure enum : __int64 has only unique values?

  • 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-06T14:11:34+00:00Added an answer on June 6, 2026 at 2:11 pm

    From your comment I’ll assume that you don’t have aggregate (combined) flags within the enum itself. In that case you can use two enums to make it much harder to make mistakes. You can still subvert the compiler but I assume that’s not the real problem here.

    enum Bit_Index
    {
        FLAG1_INDEX,
        FLAG2_INDEX,
        FLAG_FANCY_INDEX,
        LAST_INDEX
    };
    
    #define DECLARE_BIT_VALUE(att) att##_VALUE = 1ULL << att##_INDEX
    enum Bit_Value
    {
        DECLARE_BIT_VALUE(FLAG1),
        DECLARE_BIT_VALUE(FLAG2),
        DECLARE_BIT_VALUE(FLAG_FANCY),
    
        // Declared NOT using the macro so we can static assert that we didn't forget
        // to add new values to this enum.
        LAST_BIT   // Mainly a placeholder to prevent constantly having to add new commas with new ids.
    };
    #undef DECLARE_BIT_VALUE
    

    Then in an implementation file you static_assert to make sure the enums don’t get misaligned:

    // Make sure to the best of our abilities that we didn't mismatch the index/bit enums.
    BOOST_STATIC_ASSERT((LAST_BIT - 1) == (1U << (LAST_INDEX - 1)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a big database, about 800 tables. In this database there is
I'm working on a project for school, we use visual studio 2008 there and
I use Visual studio 2008. In my form there is a System.Windows.Forms.WebBrowser control. I
I have a client which would like to use SQL 2008 FTS...but I was
I have use SSRS 2008 before installing SharePoint 2010. I dig around that there
i use visual studi 2008. (c++) in my switch case a wanted to create
i use visual studio 2008, and i chose a .cpp in visual c++ at
I use Visual Studio 2008 and it really makes me crazy how it shows
I use SQL Server 2008 and have a table with 5 char typed columns.
1) I use Visual Studio 2008 (C#) 2) I want my desktop application to

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.