← Back to team overview

cuneiform team mailing list archive

Re: pointer and integer size

 

On Thu, Aug 21, 2008 at 7:14 PM, Alex Samorukov <samm@xxxxxxxxxxx> wrote:

> There are many places in code where pointer is casted to integer type. It`s
> ok in i386 (where size of ptr and int is the same, 4 bytes), but could be a
> problem on amd64. I can replace such casts with long type which is 32 bits
> on i386 and 64 on x86_64. Is it ok, or i misses something?

Use should use intptr_t instead of long (and uintptr_t instead of
unsigned long). There are two reasons:

1. Long is strictly speaking not portable. It could be any size. The
sizes you mention just happen to hold true on some (most?) platforms.

2. Using intptr_t type makes it clear that the variable is a pointer
converted to a number rather than plain number. Doing this via a type
rather than reverse polish notation (that seems so unfortunately
popular among Windows programmers) is a lot saner.



References