我应该使用什么类型对于C枚举的二进制重新presentation? [英] What type should I use for binary representation of C enum?
问题描述
据我了解C枚举是无符号整数,但这可以通过实现而不同。
我应该使用什么类型的二进制重新presentation枚举?
As I know C enum is unsigned integer, but this may vary by implementation. What type should I use for the enum in binary representation?
* PS
二重presentation是指字节数组。我想序列化枚举值到插座与其他程序,操作间。
*PS 'binary representation' means byte-array. I want to serialize enum values to socket to inter-operate with other programs.
推荐答案
这是由编译器使用 INT
重新present一个枚举
类型或长
如果 INT
不足以容纳所有值的枚举
。
It's up to the compiler to use an int
to represent an enum
type, or a long
if an int
is not sufficient to hold all the values of the enum
.
如果你知道你的所有枚举
值可以重新通过psented $ P $ INT
,那么你可以放心地使用 INT
作为你的枚举
值的二进制重新presentation。
If you know that all your enum
values can be represented by an int
, then you can safely use int
as the binary representation of your enum
values.
这篇关于我应该使用什么类型对于C枚举的二进制重新presentation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!