pointer-type args: cast appropriately to be 64-bit compatible
Using void pointers as universal arguments is widely used. However, when compiling a 64-bit target, the compiler doesn't like when an int is converted to a pointer and vice versa despite the presence of a cast. This is due to a width mismatch between ints (32 bits) and pointers (64 bits). The trick is to cast to a widening integer type such as intptr_t and then cast to void*. When appropriate, the INT_TO_POINTER macro is used instead of this double cast to make things clearer. The converse with POINTER_TO_INT is also done which also serves as good code annotations. While at it, remove unneeded casts to specific pointer types from void* in the vicinity, and move to typed variable upon function entry to make the code cleaner. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
5f5c9a5962
commit
6311766d9a
24 changed files with 120 additions and 112 deletions
|
@ -129,7 +129,7 @@ static struct {
|
|||
/*entry of contexts*/
|
||||
static void tringbuf_put(void *p)
|
||||
{
|
||||
int index = (int)p;
|
||||
int index = POINTER_TO_INT(p);
|
||||
/**TESTPOINT: ring buffer put*/
|
||||
int ret = ring_buf_item_put(pbuf, data[index].type, data[index].value,
|
||||
data[index].buffer, data[index].length);
|
||||
|
@ -142,7 +142,7 @@ static void tringbuf_get(void *p)
|
|||
u16_t type;
|
||||
u8_t value, size32 = DATA_MAX_SIZE;
|
||||
u32_t rx_data[DATA_MAX_SIZE];
|
||||
int ret, index = (int)p;
|
||||
int ret, index = POINTER_TO_INT(p);
|
||||
|
||||
/**TESTPOINT: ring buffer get*/
|
||||
ret = ring_buf_item_get(pbuf, &type, &value, rx_data, &size32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue