enum枚举在数组下标的一个用法

来源:岁月联盟 编辑:猪蛋儿 时间:2012-07-18

某枚举定义:

enum {

OV_720P,
OV_2M,
OV_3M,
OV_5M,
};

 

 

数组下标使用:

if (width == ov_resolutions[OV_720P].width) {

} else if (width == ov_resolutions[OV_2M].width) {

} else if (width == ov_resolutions[OV_3M].width) {

} else if (width == ov_resolutions[OV_5M].width) {

} else { 
return -EINVAL; www.2cto.com
}

 

优点:枚举内容可以动态增删改,区别于宏定义的定值;使用方便。


作者lifeiaidajia

图片内容