【发布时间】:2017-05-20 15:41:13
【问题描述】:
我正在尝试在 C 中使用 QT 在 C++ 中做类似的事情。 这是 C++ 代码的一部分:
typedef struct {
int order;
int type;
QString cmd;
QString res[2];
double timeout;
int exitAfterNChar;
}atCmdList_t;
atCmdList_t atCmdList[] = {
{0,0, "ATI", {"", ""}, 1, -1},
{0,0, "AT+GSN", {"", ""}, 1, -1},
{0,0, "AT+COPS?", {"+COPS: 0,0,\"vodafone IT\",2", ""}, 1, -1}
};
我正在尝试用 C 语言制作类似的东西。 我知道我可以这样做:
const char s_00[] = {""};
const char s_01[] = {"ATI"};
const char s_02[] = {"AT+GSN"};
const char s_03[] = {"AT+COPS?"};
typedef struct {
int order;
int type;
const char * cmd;
const char * res[2];
double timeout;
int exitAfterNChar;
} atCmdList_t;
atCmdList_t atCmdList[] = {
{0,0, s_01, {s_00, s_00}, 1, -1},
{0,0, s_02, {s_00, s_00}, 1, -1},
....
};
但这不像 C++ 方式那样优雅和清晰。 我的“任务”是制作或找到一个使代码尽可能具有可读性的预编译器宏。
有什么建议吗?
【问题讨论】:
标签: c arrays string coding-style