Skip to content

Commit 5f5c9a5

Browse files
Nicolas Pitreandrewboie
Nicolas Pitre
authored andcommitted
INT_TO_POINTER macros: make 64-bit compatible
The INT_TO_POINTER and POINTER_TO_INT macros must accommodate larger pointers on 64-bit systems that don't fit into an int. In the INT_TO_POINTER case, we have to use an extra cast to intptr_t as an intermediate widening type to avoid complaints from the compiler when converting from an int. This change makes no difference on 32-bit systems. Signed-off-by: Nicolas Pitre <[email protected]>
1 parent 1c84d7c commit 5f5c9a5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

include/misc/util.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
#include <zephyr/types.h>
2020
#include <stdbool.h>
2121

22-
/* Helper to pass a int as a pointer or vice-versa.
23-
* Those are available for 32 bits architectures:
24-
*/
25-
#define POINTER_TO_UINT(x) ((u32_t) (x))
26-
#define UINT_TO_POINTER(x) ((void *) (x))
27-
#define POINTER_TO_INT(x) ((s32_t) (x))
28-
#define INT_TO_POINTER(x) ((void *) (x))
22+
/* Helper to pass a int as a pointer or vice-versa. */
23+
#define POINTER_TO_UINT(x) ((uintptr_t) (x))
24+
#define UINT_TO_POINTER(x) ((void *) (uintptr_t) (x))
25+
#define POINTER_TO_INT(x) ((intptr_t) (x))
26+
#define INT_TO_POINTER(x) ((void *) (intptr_t) (x))
2927

3028
#if !(defined (__CHAR_BIT__) && defined (__SIZEOF_LONG__))
3129
# error Missing required predefined macros for BITS_PER_LONG calculation

0 commit comments

Comments
 (0)