Constant enum size no matter the number of enumerated values

后端 未结 6 1537
慢半拍i
慢半拍i 2020-12-16 16:14

Why is the size of an enum always 2 or 4 bytes (on a 16- or 32-bit architecture respectively), regardless of the number of enumerators in the type?

Does

6条回答
  •  离开以前
    2020-12-16 16:49

    An enum is not a structure, it's just a way of giving names to a set of integers. The size of a variable with this type is just the size of the underlying integer type.

提交回复
热议问题