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

Confusing definition

C:\Nordic Semiconductor\nrf51_sdk_v4_4_1_31827\nrf51822\Include\ble\softdevice\ble_gatts.h


typedef struct {
  uint16_t     handle;    /**< Attribute Handle. */
  uint8_t       op;          /**< Type of write operation, see @ref BLE_GATTS_OPS. */
  ble_gatts_attr_context_t    context;     /**< Attribute Context. */
  uint16_t      offset;      /**< Offset for the write operation. */
  uint16_t      len;          /**< Length of the incoming data. */
  uint8_t       data[1];    /**< Incoming data, variable length. */
} ble_gatts_evt_write_t;

My question is how to interpret the element data[1]? Is it just uint8_t *data(C-wise it is)? If so why is it defined in such a way? Especially with the size of the data array as one with the following comment about its variable length which all together makes this definition very confusing.

Thanks.

Parents
  • I think the confusion here is about the comment associated with the struct member data. It is clearly an array of length one, but the comment documenting it says it is variable length. If data were more than one element long the it could be undestood that the maximum expected size was always allocated but not always used, but here data is only one element. I suppose this struct could be populated with zero or one elements in data which would make it variable length.

    So the questions:

    1. Is it valid for length to be zero, implying data should be ignored?
    2. is it valid for length to be one, implying data contains a single element?
    3. If zero length is not valid, is the comment stating that data is variable length erroneous (i.e. the result of copying a template, pasting, editing names, and not updating the comments)?
  • Matt, are you saying that length can't exceed one byte? It seems to me wrong... Yet we have another ambiguity...

Reply Children
No Data
Related