1

I'm working on a smart meter project, ARM, keil compiler. I want to compile some of the more complex logic under g++ to run regression tests. I'm having a problem with some include files defining the interface to WMBus stack we purchased.

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 is defined in a compiler sensitive include file:

#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__

And I always get the following error messages:
error: types may not be defined in parameter types

error: typedef declaration invalid in parameter declaration

I can so no way around this other than by editing the include file to remove the PACKED_STRUCT. Obviously I won't edit the files directly, I'll copy them, edit them, and use the -I directive to make it find my modified files under G++

The error message seems to be saying you cannot declare a type as an argument to a macro?

Note even if I redeclare:

#define PACKED_STRUCT(__declaration__, __name__) \
  __declaration__ __name__

I am using the -std=c++11 flag to g++ but removing this flag solves nothing, but makes a system include fail

Is there any way I can define PACKED_STRUCT to make the unmodified code compile under g++?

Francis Cagney
  • 301
  • 1
  • 10

1 Answers1

0

@LP You are right, though I'm not sure why right now. This code compiles: I must have a wrong include file slipping through somehow.

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;
Francis Cagney
  • 301
  • 1
  • 10