Since ints
and pointers are the same size in the ILP32 environment, a lot of code relies on this assumption. Pointers are often cast to int
or unsigned int
for address arithmetic. Instead, pointers could be cast to long
because long
and pointers are the same size in both ILP32 and LP64 worlds. Rather than explicitly using unsigned long
, use uintptr_t
instead because it expresses the intent more closely and makes the code more portable, insulating it against future changes.
char *p; p = (char *) ((int)p & PAGEOFFSET); % warning: conversion of pointer loses bits
Suggested use:
char *p; p = (char *) ((uintptr_t)p & PAGEOFFSET);