我正在做一个智能电表项目,ARM,keil编译器。我想在g++下编译一些比较复杂的逻辑来运行回归测试。我遇到了一些定义我们购买的 WMBus 堆栈接口(interface)的包含文件的问题。
PACKED_STRUCT( typedef struct S_WMBUS_ADDR_T
{
/*! Manufacturer ID */
uint8_t pc_manufr[WMBUS_ADDR_MANUFR_LEN];
/*! Ident number */
uint8_t pc_ident[WMBUS_ADDR_IDENT_LEN];
/*! Version */
uint8_t c_version;
/*! Type */
uint8_t c_type;
}, s_wmbus_addr_t);
PACKED_STRUCT 在编译器敏感的包含文件中定义:
#elif defined (__GNUC__)
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __attribute__ ((__packed__)) __name__
...
#elif defined(__arm__)
#ifdef __ARMCC_VERSION
#define PACKED_STRUCT(__declaration__, __name__) \
__packed __declaration__ __name__
而且我总是收到以下错误消息:
错误:参数类型中可能未定义类型
错误:参数声明中的 typedef 声明无效
除了编辑包含文件以删除 PACKED_STRUCT 之外,我别无他法。显然我不会直接编辑文件,我会复制它们,编辑它们,并使用 -I 指令让它在 G++ 下找到我修改的文件
错误消息似乎是说您不能将类型声明为宏的参数?
即使我重新声明也要注意:
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __name__
我在 g++ 中使用 -std=c++11 标志,但是删除这个标志没有解决任何问题,反而使系统包含失败
有什么方法可以定义 PACKED_STRUCT 使未修改的代码在 g++ 下编译?
最佳答案
@LP 你是对的,虽然我现在不确定为什么。此代码编译: 我一定是有一个错误的包含文件以某种方式漏掉了。
typedef unsigned char uint8_t;
#define WMBUS_ADDR_MANUFR_LEN 4
#define WMBUS_ADDR_IDENT_LEN 4
#define PACKED_STRUCT(__declaration__, __name__) \
__declaration__ __attribute__ ((__packed__)) __name__
PACKED_STRUCT( typedef struct S_WMBUS_ADDR_T
{
/*! Manufacturer ID */
uint8_t pc_manufr[WMBUS_ADDR_MANUFR_LEN];
/*! Ident number */
uint8_t pc_ident[WMBUS_ADDR_IDENT_LEN];
/*! Version */
uint8_t c_version;
/*! Type */
uint8_t c_type;
}, s_wmbus_addr_t);
s_wmbus_addr_t hello;
关于c - 获取嵌入式 PACKED_STRUCT 定义以在 g++ 下编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38713823/