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

2014-11-23 23:40:05 · 作者: · 浏览: 8

某枚举定义:

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