Skip to content
Browse files

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 <>
  • Loading branch information...
Nicolas Pitre authored and andrewboie committed May 21, 2019
1 parent 1c84d7c commit 5f5c9a596210ca48ac22ab21d9a8e411ad1c8fd6
Showing with 5 additions and 7 deletions.
  1. +5 −7 include/misc/util.h
@@ -19,13 +19,11 @@
#include <zephyr/types.h>
#include <stdbool.h>

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

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

0 comments on commit 5f5c9a5

Please sign in to comment.
You can’t perform that action at this time.