对于所有编译器,C 中的默认枚举值是否相同? [英] Are default enum values in C the same for all compilers?

查看:11
本文介绍了对于所有编译器,C 中的默认枚举值是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在声明如下所示的枚举时,是否所有 C 编译器都将默认值设置为 x=0y=1z=2 在 Linux 和 Windows 系统上?

When declaring an enum as shown below, do all C compilers set the default values as x=0, y=1, and z=2 on both Linux and Windows systems?

typedef enum {
    x,
    y,
    z
} someName;

推荐答案

是的.除非您在枚举定义中另外指定,初始枚举器的值始终为零,并且每个后续枚举器的值都比前一个枚举器大 1.

Yes. Unless you specify otherwise in the definition of the enumeration, the initial enumerator always has the value zero and the value of each subsequent enumerator is one greater than the previous enumerator.

这篇关于对于所有编译器,C 中的默认枚举值是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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