开发者

How to specify the integral type for my enum type like in C#?

开发者 https://www.devze.com 2023-01-12 07:29 出处:网络
In C# I can wr开发者_如何学Pythonite something like this: enum MyEnum : byte { Value1, Value2, Value3 }

In C# I can wr开发者_如何学Pythonite something like this: enum MyEnum : byte { Value1, Value2, Value3 } and the integral type of MyEnum will be byte.

In Objective-C I want the size of MyEnum to be 1 byte. How can I do it?


You can't do it, the underlying type for enums will be chosen for you by the compiler.

If you need specific sizes, use a suitable type (e.g. uint8_t) for your variables and make sure the values in the enumeration fit in that types value range.

0

精彩评论

暂无评论...
验证码 换一张
取 消