duplicate designator is not allowed C/C++ (2906)

Hi,

There is code for vendor model element creation in nCS provided Chat client sample, as in below:

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_CHAT_CLI(&chat))),
};

This works fine in "model_handler.c",

But when I import the same code to the file "model_handler.cpp", I get a build error saying 

On : 

BT_MESH_ELEM(

I cannot avoid C++ here, kindly suggest for me to solve this.
Thanks,
Ubaid
  • Try initializing each member of bt_mesh_elem without using the BT_MESH_* helper macros. 

    Or initialize each member individually in model_handler_init

  • Hi,


    Try initializing each member of bt_mesh_elem without using the BT_MESH_* helper macros. 

    I tried doing this As in below:

     static bt_mesh_elem elementsx = {.loc=1, .model_count=2, .vnd_model_count=1,
     .models = BT_MESH_MODEL_LIST(BT_MESH_MODEL_CFG_SRV,BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub)), 
     .vnd_models = BT_MESH_MODEL_LIST(BT_MESH_MODEL_VND_CB(BT_MESH_CORPORATION_ID, BT_MESH_MODEL_CUSTOM_SRV,
     			_bt_mesh_custom_srv_op, &(cstm_srv)->pub, BT_MESH_MODEL_USER_DATA(bt_mesh_custom_srv, cstm_srv),
     			&_bt_mesh_custom_srv_cb))
     };

    This is giving an error with the line: 

    .vnd_models = BT_MESH_MODEL_LIST(..........
    Here it says, unable to use -> operator or  *cstm_srv on BT_MESH_MODEL_USER_DATA.
    Or initialize each member individually in model_handler_init
    This Can you give me any reference if available please..?
    Thanks,
  • Hi,

    The slightly cludgy workaround to this problem is to make a C wrapper that interfaces the libraries that use designated initializers, and then only call the C wrapper from your C++ code. The C wrapper would have to refrain from using designated initializers. This might also help.

    I would suggest you take this issue to the #ble-mesh channel on zephyr's discord server. You will get more support for this kind of query there.

  • Related