-7

抱歉,我是 C 新手,甚至无法清楚地解释这个问题.. 这是代码

typedef struct _ft_device_list_info_node {
    ULONG Flags;
    ULONG Type;
    ULONG ID;
    DWORD LocId;
    char SerialNumber[16];
    char Description[64];
    FT_HANDLE ftHandle;
} FT_DEVICE_LIST_INFO_NODE;

我得到了一个指针 *chanInfo,它基本上指向结构 FT_DEVICE_LIST_INFO_NODE。我想根据 FT_DEVICE_LIST_INFO_NODE 中的标志输出某些东西,所以我决定使用“switch()”,但是我应该把什么作为 switch 的条件?提前致谢。

4

2 回答 2

3

The straight answer is this:

switch (chanInfo->Flags)
{
case Something:
    ...
    break;
}

...but I can't help feeling there's more to it than that...

If Flags is actually a bitmask, which is quite likely judging by the name, then a switch is probably the wrong thing to use. You might want to do something like this:

if (chanInfo->Flags & FLAG_ONE)
{
    // FLAG_ONE is set...
}

if (chanInfo->Flags & FLAG_TWO)
{
    // FLAG_TWO is set...
}

A switch is for mutually exclusive cases, whereas flags are usually not mutually exclusive.

于 2013-05-22T20:44:27.667 回答
0

这是我要写的代码:

switch(chanInfo->Flags)
{
    case value1:
        <do stuff>
        break;
    ...
}

但我强烈建议按照一些指南或书籍逐步学习。

于 2013-05-22T20:44:11.753 回答