Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerator data type

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
0
0
GB
I have an enumerator data type and assign the values as follows:

Code:
enum manualControlList
    {
        efirst       = 1 << 0,
        esecond      = 1 << 1,
        .......
        .......
	eThirtyThird    		 = 1 << 34,
	eThirtyFourth        		 = 1 << 35,
        eLast
    };

However, I think there may be a problem with this piece of code.

What is the size of an enumerator? Also, will the lines with 1 << 32; 1 << 33; 1 << 34; 1 << 35 cause problems?

Thanks or your help.

Wallace
 
enum is 32 bits.
I'm not sure if it's 64 bits on a 64-bit CPU?
 
Thanks for the reply.

Given it's 32 bits am I correct to assume so that e.g. 1 << 34 will cause errors?


Wallace
 
I don't know if it'll cause an error, but it won't do what you want. The 1 will fall off the end of the enum and you'll just have 0x00000000.

1 << 31 is the highest you can go.
 
For example, VC++ 6.0 does not signal error for 1<<34 (0 assigned). But see:
C++ Std said:
7.2 Enumeration declarations
...
5 The underlying type of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. It is implementation-defined which integral type is used as the underlying type for an enumeration 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.
 
Ok thanks for all the replies.

Can you suggest something else that I can use instead of an enumerator?
 
use instead of enumerator?(!) What for? const declarations...
 
>Can you suggest something else that I can use instead of an enumerator?

An iterator?

/Per
[sub]
www.perfnurt.se[/sub]
 
wallaceoc80 said:
Can you suggest something else that I can use instead of an enumerator?
Maybe a bitset? That's in the STL <bitset> header BTW.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top