c**********e 发帖数: 2007 | 1 What is the size of an enumeration type?
a) sizeof(size_t)
b) 2
c) 4
d) sizeof(int)
e) implementation-defined |
x***y 发帖数: 633 | 2 actually, enumerator can be cast to int; but inside a class, enumerator is
like static, no memory won't be allocated for a particular object... |
c**********e 发帖数: 2007 | 3 So the answer is e)?
【在 x***y 的大作中提到】 : actually, enumerator can be cast to int; but inside a class, enumerator is : like static, no memory won't be allocated for a particular object...
|
x***y 发帖数: 633 | 4 Not sure...It may be stored in data segment, but it must have a size at
least sizeof(int) to be able to be converted to int...
【在 c**********e 的大作中提到】 : So the answer is e)?
|
c**********e 发帖数: 2007 | 5 The absolute size of integral types is generally implementation defined, and
as this question further shows, the size of an enumeration is not even
required to be the size of a specific integral type.
d) sizeof(int)
This is incorrect. This is the common wrong answer. Enumeration types may
allow values that will not fit in the range of an int.
e) implementation-defined
This is correct. The actual size of an enumeration type depends in part on
the magnitude and sign of the enumerator values. Ho |
x***y 发帖数: 633 | 6 good to know....
and
on
to
【在 c**********e 的大作中提到】 : The absolute size of integral types is generally implementation defined, and : as this question further shows, the size of an enumeration is not even : required to be the size of a specific integral type. : d) sizeof(int) : This is incorrect. This is the common wrong answer. Enumeration types may : allow values that will not fit in the range of an int. : e) implementation-defined : This is correct. The actual size of an enumeration type depends in part on : the magnitude and sign of the enumerator values. Ho
|
P********l 发帖数: 452 | 7 Cool bean, dude.
and
may
on
rules to
【在 c**********e 的大作中提到】 : The absolute size of integral types is generally implementation defined, and : as this question further shows, the size of an enumeration is not even : required to be the size of a specific integral type. : d) sizeof(int) : This is incorrect. This is the common wrong answer. Enumeration types may : allow values that will not fit in the range of an int. : e) implementation-defined : This is correct. The actual size of an enumeration type depends in part on : the magnitude and sign of the enumerator values. Ho
|
l****5 发帖数: 95 | 8 According to Bjarne Stroustrup's book "The C++ Programming language
(special edition)" page 78 (the very top):
"The sizeof an enumeration is the sizeof some integral type that can
hold its range and not larger than sizeof(int), unless an enumerator
cannot be represented as an int or as an unsigned int".
Here integral type include Boolean, character and integer types.
Please also refer the discussion here
http://stackoverflow.com/questions/1113855/is-the-sizeofenum-sizeofint-
always
defined, and
【在 c**********e 的大作中提到】 : The absolute size of integral types is generally implementation defined, and : as this question further shows, the size of an enumeration is not even : required to be the size of a specific integral type. : d) sizeof(int) : This is incorrect. This is the common wrong answer. Enumeration types may : allow values that will not fit in the range of an int. : e) implementation-defined : This is correct. The actual size of an enumeration type depends in part on : the magnitude and sign of the enumerator values. Ho
|