在C默认枚举值同样为所有的编译器? [英] Are default enum values in C the same for all compilers?

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

问题描述

在声明如下图所示,做所有的C编译器设置的默认值枚举X = 0 Y = 1 Z = 2 ?

 的typedef枚举{
    X,
    Y,
    ž
} someName;


解决方案

是的。除非你在枚举的定义另有规定,最初的枚举的值总是为零,每个后续枚举的值是一比previous枚举更大。

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;

解决方案

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天全站免登陆