I am using NCS Connect SDK version 2.6.0
I am trying to create an array of models and found a problem with using Zephry macros in C++ projects. My main.cpp is as below
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/mesh.h> #include <zephyr/sys/printk.h> int main(void) { printk("Hello Worlds! %s\n", CONFIG_BOARD); static const struct bt_mesh_model models[] = { BT_MESH_MODEL_CFG_SRV, }; return 0; }
BT_MESH_MODEL_CFG_SRV is defined in cfg_srv.h as
#define BT_MESH_MODEL_CFG_SRV \ BT_MESH_MODEL_CNT_CB(BT_MESH_MODEL_ID_CFG_SRV, \ bt_mesh_cfg_srv_op, NULL, \ NULL, 1, 0, &bt_mesh_cfg_srv_cb)
BT_MESH_MODEL_CNT_CB is defined in access.h
/** * @brief Composition data SIG model entry with callback functions * with specific number of keys & groups. * * This macro uses compound literal feature of C99 standard and thus is available only from C, * not C++. * * @param _id Model ID. * @param _op Array of model opcode handlers. * @param _pub Model publish parameters. * @param _user_data User data for the model. * @param _keys Number of keys that can be bound to the model. * Shall not exceed @kconfig{CONFIG_BT_MESH_MODEL_KEY_COUNT}. * @param _grps Number of addresses that the model can be subscribed to. * Shall not exceed @kconfig{CONFIG_BT_MESH_MODEL_GROUP_COUNT}. * @param _cb Callback structure, or NULL to keep no callbacks. */ #define BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data, _keys, _grps, _cb) \ { \ .id = (_id), \ .pub = _pub, \ .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(_keys), \ .keys_cnt = _keys, \ .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps), \ .groups_cnt = _grps, \ BT_MESH_MODEL_UUIDS_UNASSIGNED() \ .op = _op, \ .cb = _cb, \ .user_data = _user_data, \ }
Which is where the problem lies. The macro is defined for C language only and cannot be used with a C++ compiler as it uses compound literals.
Does anyone have any suggestion to resolve this impase
Appreciate any suggestions.
Thanks