什么是用C枚举的大小? [英] What is the size of an enum in C?

查看:147
本文介绍了什么是用C枚举的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一组枚举值,但我需要每个枚举值是64位宽。如果我没有记错,枚举一般是尺寸为int一样;但我想我读的地方,(至少在GCC)编译器可以使枚举他们需要保持他们的价值观的宽度。那么,是不是可以有一个枚举是64位宽?

I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide?

推荐答案

这是枚举只能保证大到足以容纳 INT 值。编译器可以自由选择的基础上定义的枚举常量使用,因此它可以选择较小型的实际类型如果可以重新present您定义的值。如果你需要一个不适合的枚举常量的 INT 您将需要使用特定的编译器的扩展这样做。

An enum is only guaranteed to be large enough to hold int values. The compiler is free to choose the actual type used based on the enumeration constants defined so it can choose a smaller type if it can represent the values you define. If you need enumeration constants that don't fit into an int you will need to use compiler-specific extensions to do so.

这篇关于什么是用C枚举的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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