What would happen if I (somehow) made an enum bigger than unsigned int?
Each item in one is assigned a numerical value, I'm guessing that is unsigned int.
Would it be boring like an error message or fun? Knowing what's allowed with naming the values there is more than enough combinations (even after removing name size limits and names for common other stuff).

What would happen if I (somehow) made an enum bigger than unsigned int?

The compiler will attempt to adjust the underlying type according to the largest enumerator value. As for defining an enumerator value lager than the largest possible integer, good luck trying. ;)

In Visual Studio you get an error that says "enumeration value is out of 'int' range".
I have not yet tried it with other compilers.

In gcc 3.4.6, it gives a Warning:
warning: this decimal constant is unsigned only in ISO C90
...and it will not compile

How did you manage to get a enum made that big that fast?!? And if for some magical reason I needed one bigger than unsigned long long how would I do that?

All you need is one element (or so) as you can dictate where it starts.

typedef enum {A=3000000000, A=3000000001} BLAH; //kaboom

Usually, you will find that you don't REALLY need something that big.
You can use an offset. If your range is from 3000000000 to 3000009999 all you really need is 0 to 9999 and you can add the 3000000000 to your final result if need be.

> In gcc 3.4.6, it gives a Warning:
> warning: this decimal constant is unsigned only in ISO C90

Ideally, use a more recent version of the compiler (ie. not older than the oldest maintained release).

For precise control over the integral type on which enums are based, use scoped enums.

// the integral type on which [B]one[/B] is based defaults to [B]int[/B]
// [B]two[/B] is based on [B]unsigned long long[/B], [B]three[/B] on [B]std::int_fast16_t[/B]
enum struct one { A = 100, B, C, D } ;
enum struct two : unsigned long long { A = 12345678987654321ULL , B, C, D } ;
enum struct three : std::int_fast16_t { A, B, C, D } ;

> And if for some magical reason I needed one bigger than unsigned long long how would I do that?

Such a large integral type would have to be simulated via a user defined type. For example:

struct big_int
{
    big_int( long long ) ;
    big_int operator* ( long long n ) const ;
    // etc
    // ...
};

The ennum would have to be simulated too:

struct big_enum
{
    static const big_int&& A ;
    static const big_int&& B ;
};

const big_int&& big_enum::A = big_int( std::numeric_limits<long long>::max() * 25 ) ;
const big_int&& big_enum::B = big_enum::A * 100 ;

Close to a scoped enum except that an enumerated value is an rvalue reference to const instead of a constexpr.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.