What is the size of an enum in C?

前端 未结 7 1705
无人及你
无人及你 2020-11-22 08:55

I\'m creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read

相关标签:
7条回答
  • 2020-11-22 09:34

    While the previous answers are correct, some compilers have options to break the standard and use the smallest type that will contain all values.

    Example with GCC (documentation in the GCC Manual):

    enum ord {
        FIRST = 1,
        SECOND,
        THIRD
    } __attribute__ ((__packed__));
    STATIC_ASSERT( sizeof(enum ord) == 1 )
    
    0 讨论(0)
提交回复
热议问题