所以我有一个typedef枚举类似于:

typedef enum
{
    CH1,
    CH2,
    CH3
} AIN_Ch_t;

这是在单独的文件中声明的。
所以在另一个文件中我想使用这个枚举。
以下是我认为应该是正确的:
//declare variable of type AIN_Ch_t
AIN_Ch_t channel1;
//use the variable as parameter in function compiler gives error
func1(channel1.CH1);

但当我这样做时-没有错误:
func1(CH1); //no error. compiler likes.

显然我想的都不对。有人能澄清吗?谢谢!

最佳答案

func1(channel1.CH1);

enums没有类似结构的成员。你所做的是不正确的。你能做的就是-
AIN_Ch_t channel1;
channel1=CH1;
func1(channel1);

或者第二种方式-
func1(CH1);             // directly pass CH1 to function

You can refer here to know about enums.

关于c - 使用typedef枚举成员是可能的吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32994323/

10-09 15:51