简体   繁体   中英

Problem compiling Cypress software with IAR

I've a Cypress BLE module and have compilation problem with IAR. In "ezsapi.h" are defined this macros:

#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 usually use #pragma pack(push,1) and #pragma pack(pop) and I tryed to modify the macro in:

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

With original macros the errors reported is:

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 "{"

and with my macro the errors reported is:

(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 "{"

What's the correct formula for IAR? What's escaping me?

Thanks.

There are two ways of solving this problem. My suggestion is that you use the __packed type attibute instead of #pragma pack() as this has a more well defined meaning. This, however, needs IAR language extensions to be switched on. If you can't enable language extensions or for some other reason need to use pack-pragma you have to use an alternative pragma syntax to be able to include it in a preprocessor macro. If you use _Pragma("pack(push,1)") and _Pragma("pack(pop)") you macro should work as expected. Definitions of PACKDEF for both alternatives are shown below:

#define PACKDEF(STRUCTNAME, STRUCTDEF) typedef __packed struct STRUCTDEF STRUCTNAME

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM