[英]how to search in enum type in C
我有以下代碼:
typedef enum Types{
Type_1, Type_2, Type_3
} MyTypes;
typedef union Tree{
struct {
int MyType;
}structAccessor;
} MyTree;
我正在創建這樣的樹:
MyTree* node(MyTypes MyType).......//folowwing is unnecessary
我想知道如何找到樹的類型,如下所示:
if(node->structAccessor.MyType == MyTypes[2]) //if MyType is Type_2, i want to compare this, thanks so much
C中的enum
始終為int
類型。
您可以針對任何int
進行測試,例如
if (node->structAccessor.MyType == Type_1)
盡管它們通常在switch
語句中使用
switch (node->structAccessor.MyType) {
case Type_1:
...
case Type_2:
...
case Type_3:
...
default: // error
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.