Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Although this is likely to work on many architectures, it does not provide maximum portabilityis much less portable than it could be.

Compliant Solution

On machines where pointers can be represented as integers, the types intptr_t and uintptr_t are provided for that purpose.  They are only guaranteed to be able to receive void pointers.

Code Block
bgColor#ccccff
#include <stdint.h>
enum { ALIGN_MASK = 3 };
/* ... */
char *ptr1;
char *ptr2;
/* ... */
if (((uintptr_t)(void *)ptr1 & ALIGN_BITSMASK) == ((uintptr_t)(void *)ptr2 & ALIGN_BITSMASK)) {
  /* ... */

The header inttypes.h can be used instead of stdint.h to get the integer types in a hosted environment.

...