This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

CPP conversion of model_handler.c of mesh_chat example not working

Hi Nordic team,

Please guide to resolve the error .

While trying to convert the model_handler.c to model_handler.cpp the below deceleration shows multiple compilation errors

static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(
1,
BT_MESH_MODEL_LIST(
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub)),
BT_MESH_MODEL_LIST(BT_MESH_MODEL_HELLO_BLE_COMM(&chat))),
};

Compilation Errors Are:

expected primary-expression before 'struct'
in definition of macro 'ARRAY_SIZE'
in expansion of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'
expected ')' before 'struct'
in definition of macro 'ARRAY_SIZE'
in expansion of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'
expected primary-expression before 'struct'
in definition of macro 'ARRAY_SIZE'
in expansion of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'
expected ')' before 'struct'
in definition of macro 'ARRAY_SIZE'
in expansion of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'
mesh.h


expected primary-expression before 'struct'
in definition of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'
expected ')' before 'struct'
in definition of macro 'BT_MESH_ELEM'
in expansion of macro 'BT_MESH_MODEL_LIST'

Location of Error showed at model.h : #define BT_MESH_MODEL_LIST(...) ((struct bt_mesh_model[]){ __VA_ARGS__ })

Thanks

Selvam

Parents
  • Sorry, but we don't have any experience with this. I would think you can keep a combination of .c and .cpp in your project, so not sure why you want to "convert" it to .cpp.

    Kenneth

  • Hi Kennetrh,

    Thanks for the response.

    Actually we needs to have application layer files in CPP. as below.

    So that we planned to have convert model_handler.c to model_handler.cpp.

    But unfortunately we are getting compilation on compiling  the below structure array definitions.

    static struct bt_mesh_elem HelloBleElements[] = {

              BT_MESH_ELEM(

                      1,

                      BT_MESH_MODEL_LIST(

                              BT_MESH_MODEL_CFG_SRV,

                              BT_MESH_MODEL_HEALTH_SRV(&HealthSrv, &HealthPub)),

                      BT_MESH_MODEL_LIST(BT_MESH_MODEL_HELLO_BLE_COMM(&HelloBle))),

      };

     

     

    static struct Button Buttons[4] = {

                    [0 ... 3] = { .Client = BT_MESH_ONOFF_CLI_INIT(&StatusHandler) },

    };

    Is that any possible way to resolve compilation error?

  • In my experience using C++ with the nrf SDK, a large number of compilation issues are caused by out of order or incomplete initialization of structs by the SDK macros. I tend to initialize any structs created by macros without the macro itself.

Reply Children
Related