Hello,
I am just trying to uınderstand what is happening in the belown code. It seems like casting pointers but I didnt get the
whole idea.
Can some one explain it ?
Thanks for helps
#define BLE_UUID16_DECLARE(uuid16) \
((ble_uuid_t *) (&(ble_uuid16_t) BLE_UUID16_INIT(uuid16)))
BLE header files
-
- Posts: 94
- Joined: Tue Sep 07, 2021 12:07 pm
Re: BLE header files
Expand the macros. I think this might be the ones: https://github.com/apache/mynewt-nimble ... ble_uuid.h
so
means
which is an initialized structure. The next bit,
takes the address of the structure and casts it to a more generic structure pointer.
That in turn is part of a union.
The union has four possible interpretations, depending on the ble_uuid_t at the beginning of each member of the union. The last three all look like
which embeds a ble_uuid_t, followed by more data. The first just doesn't have any more data.
I think the extra parens are required by the macro to separate ble_uuid16_t from BLE_UUID16_INIT, maybe.
Code: Select all
#define BLE_UUID16_INIT(uuid16) \
{ \
.u = { \
.type = BLE_UUID_TYPE_16, \
}, \
.value = (uuid16), \
}
Code: Select all
(ble_uuid16_t) BLE_UUID16_INIT(uuid16)
Code: Select all
(ble_uuid16_t)
{ \
.u = { \
.type = BLE_UUID_TYPE_16, \
}, \
.value = (uuid16), \
}
Code: Select all
((ble_uuid_t *) (&
Code: Select all
/** Generic UUID type, to be used only as a pointer */
typedef struct {
/** Type of the UUID */
uint8_t type;
} ble_uuid_t;
Code: Select all
/** Universal UUID type, to be used for any-UUID static allocation */
typedef union {
ble_uuid_t u;
ble_uuid16_t u16;
ble_uuid32_t u32;
ble_uuid128_t u128;
} ble_uuid_any_t;
Code: Select all
/** 16-bit UUID */
typedef struct {
ble_uuid_t u;
uint16_t value;
} ble_uuid16_t;
I think the extra parens
Code: Select all
(ble_uuid16_t)
Craige
Re: BLE header files
Thank you for your help..
Who is online
Users browsing this forum: atesin, Bing [Bot] and 133 guests