I would like to know how.
I have looked at this topic, and I understand that "The choice of type is implementation-defined.", but I am curious to know how to get 1 instead of 4.
I would like to know how.
I have looked at this topic, and I understand that "The choice of type is implementation-defined.", but I am curious to know how to get 1 instead of 4.
C++11 introduced a way to change the underlying type of an enum.
enum foo : char { ... };
enum class foo : char { ... };
Still, you're probably better off with using the default int
in most cases.
On GCC, you can also use the 'packed' attribute to tell the compiler you care more about space than word alignment / access speed:
enum foo { ... } __attribute__((packed));
There are similar hints for other compilers too.
(This is useful when trying to avoid any C++11 features that aren't yet supported by your compiler or IDE.)