如何使用与字符串相关联的 uint8_t 进行查找 table?
How to make a lookup table with uint8_t associated to a string?
我想查找 table,其中 uint8_t
关联到 string
。
你觉得我该怎么做?
这是我的代码:
static const uint16_t ReadAccess[][2] =
{
/* Value in b3b2 in byte 1, read access description */
{0x0, "ALWAYS"},
{0x1, "RFU"},
{0x2, "PROPRIETARY"},
{0x3, "RFU"}
};
您可以使用结构将具有多种类型的成员分组以创建一种新类型。
struct table_element {
uint8_t intValue;
const char* strValue;
};
static const struct table_element ReadAccess[] = {
{0x0, "ALWAYS"},
{0x1, "RFU"},
{0x2, "PROPRIETARY"},
{0x3, "RFU"}
};
我想查找 table,其中 uint8_t
关联到 string
。
你觉得我该怎么做?
这是我的代码:
static const uint16_t ReadAccess[][2] =
{
/* Value in b3b2 in byte 1, read access description */
{0x0, "ALWAYS"},
{0x1, "RFU"},
{0x2, "PROPRIETARY"},
{0x3, "RFU"}
};
您可以使用结构将具有多种类型的成员分组以创建一种新类型。
struct table_element {
uint8_t intValue;
const char* strValue;
};
static const struct table_element ReadAccess[] = {
{0x0, "ALWAYS"},
{0x1, "RFU"},
{0x2, "PROPRIETARY"},
{0x3, "RFU"}
};