使用 IAR 编译赛普拉斯软件时出现问题



我有一个赛普拉斯BLE模块,并且在IAR上遇到了编译问题。 在"ezsapi.h"中定义了以下宏:

#ifdef __GNUC__
/* standard GNU C */
#ifdef _WIN32
/* MinGW, Cygwin, TDM-GCC, etc. */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__,gcc_struct)) STRUCTNAME
#else
/* generic gcc */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__)) STRUCTNAME
#endif
#define ALIGNED __attribute__((aligned(0x4)))
#else
/* Microsoft Visual C++ */
#define __PACKDEF(STRUCTNAME, STRUCTDEF) __pragma(pack(push, 1)) STRUCTDEF __pragma(pack(pop)) STRUCTNAME
#define ALIGNED
#endif

IAR 通常使用 #pragma pack(push,1(#pragma pack(pop(,我尝试在以下位置修改宏:

#define __PACKDEF(STRUCTNAME, STRUCTDEF) #pragma(pack(push, 1)) STRUCTDEF #pragma(pack(pop)) STRUCTNAME

对于原始宏,报告的错误是:

ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"

使用我的宏,报告的错误是:

(69 is the line where the macro is located)
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"

IAR 的正确公式是什么? 我逃脱了什么?

谢谢。

有两种方法可以解决这个问题。我的建议是使用__packed类型的属性而不是#pragma pack()因为这具有更明确的含义。但是,这需要打开 IAR 语言扩展。如果无法启用语言扩展或出于其他原因需要使用包编译指示,则必须使用替代编译指示语法才能将其包含在预处理器宏中。如果使用_Pragma("pack(push,1)")_Pragma("pack(pop)")则宏应按预期工作。两种备选方案的PACKDEF定义如下所示:

#define PACKDEF(STRUCTNAME, STRUCTDEF) typedef __packed struct STRUCTDEF STRUCTNAME
#define PACKDEF(STRUCTNAME, STRUCTDEF)  _Pragma("pack(push,1)") typedef struct STRUCTDEF STRUCTNAME _Pragma("pack(pop)")

最新更新