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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:51:27+00:00 2026-05-18T00:51:27+00:00

How to find the range of enums ? I have got two versions which

  • 0

How to find the range of enums ?
I have got two versions which state it differently when the lowest value is negative.Stroustrup says that for

 enum e3 { min = -10 , max = 1000000 }; // range -1048576:1048575

but
C++ Primer Plus 5th edition says

for eg if the smallest enumerator is -6, the next power of two [times a minus sign] is -8, and thus the lower limit is -7

I am confused which is correct ?

  • 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-18T00:51:28+00:00Added an answer on May 18, 2026 at 12:51 am

    I believe both are correct (see below for Primer’s definition, though), depending on how compatible you want to are. The formal definition is

    For an enumeration where e min is the smallest enumerator and e max is the largest, the values of the enumeration are the values of the underlying type in the range b min to b max , where b min and b max are, respectively, the smallest and largest values of the smallest bit-field that can store e min and e max .

    For negative numbers, the question is what representation we use. The footnote to it says

    On a two’s-complement machine, b
    max is the smallest value greater than or equal to max (abs(e min ) − 1 ,abs(e max ) ) of the form
    2 M − 1; b is zero if e is non-negative and − (b + 1 ) otherwise.

    If you assume sign magnitude or one’s complement then the example enumeration’s range is -1048575:1048575. For two’s complement you get one more in the negative range. Primer’s definiton lacks the maximum enumerator value, so I’m not sure how it comes to lower limit -7. If you want to be maximum compatible with other implementations, I would go with -1048575:1048575.

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

Sidebar

Related Questions

I have the date range (two UNIX timestamps) and I need to find point(s)
I have used the Find_Range function from OzGrid which returns a Range object with
Is there an accepted efficient way to find the range (ie. max value -
I have asked to find the last row in a Range with the following:
I have been trying to find how to calculate the Floating/Double precision/range numbers -3.402823e38
I have a list of ranges. Each range has a from and to value,
I have a method to find number in range of iterator like below. I
I'm wondering if in MySQL you are able to find a range within values
Thought my range of search options would easily find this. I wish to combine
I have a range of C functions: const char* find_string(uint8_t id); int32_t find_int32(uint8_t id);

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.