Sizeof(struct) call returns invalid struct size

halfro
Posts: 18
Joined: Sat Jul 15, 2017 11:13 am

Sizeof(struct) call returns invalid struct size

Postby halfro » Thu Sep 07, 2017 11:56 am

I am writing down the structure representing the user descriptor value 0x2904:

Reference is here:https://www.bluetooth.com/specification ... format.xml

Code: Select all

typedef struct
{
    uint8_t _format;
    int8_t _exponent;
    uint16_t _unit;
    uint8_t _namespace;
    uint16_t _description;
} presentation_t;
I initialise it as below as an example:

Code: Select all

static presentation_t utf8_presentation = 
{
    ._format=25,
    ._exponent=0,
    ._unit=0,
    ._namespace=0,
    ._description=0,
};
I pass it to a gatt attribute table as below:

Code: Select all

    [USAGE_IDX_DISPLAY_STRING_CFG_1]     	=    
    {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&usage_character_char_presentation_uuid, ESP_GATT_PERM_READ,
     sizeof(utf8_presentation),sizeof(utf8_presentation), (uint8_t *)&utf8_presentation}}
When I debug and check the size returned by the sizeof operator I obtain 8 bytes instead of 7. The same also reflects on nrf-connect app(Incorrect data length,7 bytes expected). Any reason for this? My local idf repo is at v3.0-dev

halfro
Posts: 18
Joined: Sat Jul 15, 2017 11:13 am

Re: Sizeof(struct) call returns invalid struct size

Postby halfro » Thu Sep 07, 2017 12:17 pm


halfro
Posts: 18
Joined: Sat Jul 15, 2017 11:13 am

Re: Sizeof(struct) call returns invalid struct size

Postby halfro » Thu Sep 07, 2017 6:25 pm

Appropriate definition:

Code: Select all

typedef struct
{
    uint8_t _format;
    int8_t _exponent;
    uint16_t _unit;
    uint8_t _namespace;
    uint16_t _description;
} __attribute__ ((packed)) presentation_t;

Who is online

Users browsing this forum: No registered users and 251 guests