Reputation: 495
TL;DR How many elements could an enumerator hold, and would that number be larger than a 64-bit or 96-bit number?
In my experience with C and C++, I've found that the largest variable type that will compile is 96 bits (12 bytes) and even that is a non-standard addition by GCC 64 bit. So, I started thinking about enumerators and how large an enumerator could be. Let's say, for the sake of simplicity, I have an enumerator-type called foo:
enum foo
{
//Insert types here
}
And that we have the enumerator filled with an ENORMOUS amount of types:
enum foo
{
type1,
type2,
type3,
//Some keyboard-time later....
type9999999999999999999999999999999999999997,
type9999999999999999999999999999999999999998,
type9999999999999999999999999999999999999999,
type10000000000000000000000000000000000000000 //That's fifty zeroes
}
Would that even compile? (Yes,I know compilation would give me a good idea of how long an ice age lasts, but still) And would I be able to declare a foo
with the value of every single one of the type
s?
Upvotes: 0
Views: 72
Reputation: 1769
From the standard:
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.
So for standard conforming compiler the program should not compile if there is no integral type that can hold all the enumerator values.
This is from the working draft https://isocpp.org/std/the-standard, but I doubt that part has changed.
Upvotes: 2