我应该使用什么类型对于C枚举的二进制重新presentation? [英] What type should I use for binary representation of C enum?

查看:173
本文介绍了我应该使用什么类型对于C枚举的二进制重新presentation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆