What happens if an enumeration cannot fit into an integral type?

I came across this question about the main types of enums, where the answers quote Standard C ++ 7.2 / 5 as:

The basic type of an enumeration is an integral type that can represent all the values ​​of an enumeration defined in an enumeration. An implementation is defined that is an integral type as the base type for the enumeration, except that the base type must not be greater than int if the enumerator value cannot be placed in int or unsigned int.

This is pretty clear for all reasonable cases. But what happens if I make an enum so ridiculously large that it can't even fit in for a long time?

(I don’t know why this has ever happened in practice, but maybe I feel destructive and have a free day)

Is this behavior a standard?

+12
c ++ enums types size
Sep 21 '16 at 15:30
source share
1 answer

Behavior

enum foo : int { bar = INT_MAX, oops }; 

and similar undefined.

I cheated a bit by forcing the int type, but the same goes for the largest integral type available on your platform.

+10
Sep 21 '16 at 15:33
source share



All Articles