What is the type of enum constant when used outside the definition of unumed enum?
Consider the following code:
#include <iostream>
enum modes
{
begin = 0,
end = 1
};
int main()
{
std::cout << std::boolalpha
<< std::is_same<unsigned int, typename std::underlying_type<modes>::type>::value
<< std::endl;
std::cout << sizeof(modes) << std::endl;
std::cout << (-100 + end) << std::endl;
}
This gives on my machine:
true
4
-99
Now, if I only changed the value of any other enumerator, beginto 2147483648, then my output would be:
true
4
4294967197
Apparently, this means that the type endhas changed from intto unsigned int, even the base type is modesstill the same (i.e. unsigned int).
Are there special rules for integral promotions regarding transfers?
source
share