Reputation: 135
Can I set some options in Visual Studio 2010 to change enum size to 1 byte? Code changes is prohibited. I need some compilation options.
Upvotes: 1
Views: 1059
Reputation: 180316
There are two logically different sizes you could be talking about: the size of the enum constants associated with a given enum type, or the size of an object whose own type is the enum type. For example, given
enum example { ONE, TWO };
enum example enum_variable;
the first declaration declares both the type enum example
and the constants ONE
and TWO
.
Perhaps surprisingly, the constants do not have type enum example
; rather they have type int
, and they will therefore consume whatever amount of space an int
requires (C99 6.7.2.2/3).
On the other hand, enum_variable
does have type enum example
, and more likely it is actually the size of this type that you hope to affect. C gives some constraints there, but designates the specific choice to be implementation-defined (C99 6.7.2.2/4). That's a bit hopeful because it requires implementations to in fact document their choice, and the VS 2010 docs do so if you drill down far enough. Unfortunately for you, the docs say that a variable of enum
type is an int
. If the docs are to be believed, then, the size of enum
variables is not adjustable in VS 2010.
Upvotes: 3