enum 枚举 在 数组下标的 一个用法
某枚举定义:
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;
}
优点:枚举内容可以动态增删改,区别于宏定义的定值;使用方便。