How using a pointer and definition from a #define in C -
i wondering how gattcharcfg_t within defined snippet being used.
here #define snipped:
// client characteristic configuration table (from ccc attribute value pointer) #define gatt_ccc_tbl( pvalue ) ( (gattcharcfg_t *)(*((ptr_type)(pvalue))) ) and here how being accessed in couple spots in given code:
// characteristic configuration: voltage static gattcharcfg_t *voltdataconfig; // allocate client characteristic configuration table voltdataconfig = (gattcharcfg_t *)icall_malloc(sizeof(gattcharcfg_t) * linkdbnumconns); if (voltdataconfig == null) { return (blememallocerror); } i guess not understanding mechanics of how being accessed. appreciate more thorough explanation diving c.
( (gattcharcfg_t *)(*((ptr_type)(pvalue))) ) (ptr_type)(pvalue)- cast pvalue ptr_type (pointer)*((ptr_type)(pvalue))- @ memory location pointed pointer(gattcharcfg_t *)(*((ptr_type)(pvalue)))- pointer pointinggattcharcfg_tstructure (could array ofgattcharcfg_t) instead of void *
gatt_ccc_tbl macro shortcut having write out conversion. respect other code in post,
voltdataconfig = (gattcharcfg_t *)icall_malloc(sizeof(gattcharcfg_t) * linkdbnumconns); sizeof(gattcharcfg_t)- take size ofgattcharcfg_t, e.g., 23 bytes* linkdbnumconns- multiply linkdbnumconns, e.g., 100 making 2300 bytesicall_malloc(..)- allocate memory(gattcharcfg_t *)- cast location in memory pointergattcharcfg_tstructures
update. looks code bluetooth stack, in case
typedef struct { uint16 connhandle; //!< client connection handle uint8 value; //!< characteristic configuration value client } gattcharcfg_t; so gatt_ccc_tbl( pvalue ) take pointer value pvalue , turn points to 1 or more gattcharcfg_t structures - array of these since _tbl "table".
Comments
Post a Comment