What type of declaration is "static const struct bt_data ad[] = {X,Y,..}"?

I am.a beginner in BLE embedded development, and I have a question regarding the following declaration that is going to be "the advertisement data"
In specific, 

static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
I know that ad[] is an array, but I am confused regarding what is before that. Typically, I expect from the C language syntax that a data type should be placed prior to the name, but here there is something between "struct" and "ad". Any help or idea is much appreciated.

Thanks.
Parents
  • Hello,

    Thank you for contacting DevZone at NordicSemi.

    The line of code that you have mentioned:

    static const struct bt_data ad[] = {}
    

    is declaration of an array.

    The name of array is ad

    The type of array (or the type of data it can store) is bt_data

    where bt_data is a struct that has been defined in header files.

    In the sample code (e.g peripheral_uart) opened in the VS-Code, if you hover over the bt_data, it will show you its description

    Moreover, you can right click on bt_data and goto the definition of where the struct is defined in the header file.

    So here you see that the bt_data is struct defined in bluetooth.h and its subfields are as shown below:

    Hope it answers your query.

    BR,

    Naeem

  • Thanks Naeem, I understand your points. However, why we need to declare the "struct" type two times if bt_data is already defined as a structure. As you said if you go to the definition, it says struct bt_data { }. Thanks. 

Reply Children
Related