GCC/Clang/MSVC extension for specifying C enum size?

后端 未结 2 1032
日久生厌
日久生厌 2021-01-22 05:36

Is there any extension feature to specify size of C enum on each compiler?

  • GCC
  • Clang
  • MSVC
2条回答
  •  醉酒成梦
    2021-01-22 05:49

    C++11 introduced a standardized way to do this, but since this is C you'll have to settle for a more simple method of making the last enum INT_MAX or a value thats large enough so that only the type you want can hold it (this is what the DirectX SDK does). Unfortunatly there is no way to force a maximum size (at least not without compiler specific extensions).

提交回复
热议问题