Yoichi's diary
2012-03-16
_ enum size in C
enum定数はint型だが、enum自体のサイズは処理系依存。たとえば#include <stdio.h> enum EnumTest { ENUM_TEST_VALUE }; int main() { printf("%d, %d\n", sizeof(enum EnumTest), sizeof(ENUM_TEST_VALUE)); return 0; }を手元の Windows7 環境で gcc -fshort-enums でコンパイルして実行すると "1, 4" と出力された(-fshort-enums つけなければ "4, 4" になった)。使ったコンパイラは
$ gcc --version gcc.exe (TDM-1 mingw32) 4.4.0 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[ツッコミを入れる]