* Casting 64-bit pointers to integers
@ 2009-05-22 9:30 Michael David Crawford
2009-05-22 9:41 ` Samuel Thibault
0 siblings, 1 reply; 4+ messages in thread
From: Michael David Crawford @ 2009-05-22 9:30 UTC (permalink / raw)
To: xen-devel
In building on my 64-bit Xeon box, I see a lot of warnings about casting
between pointers and integers of different sizes.
Sometimes it can cause fatal compiler error.
Is there a reasonably portable way to make such casts?
The conventional wisdom is that ints are supposed to be the natural
machine word size. But even that isn't always the case - much gnashing
of teeth resulted in the two most popular compilers for the 68000
Macintosh having different int sizes.
There are typedefs for integers with specific numbers of bits, but
that's not what we want. If we're building for 32-bit, we want a 32-bit
integer, and if we're building for 64-bit, we want a 64-bit integer.
Is there any kind of standardized integer type which is guaranteed to be
the same size as a pointer?
What might even be worse is that the mismatch is on purpose for some
reason, say that some structure has a field that simply *must* be
32-bits, but we're trying to wedge a 64-bit pointer into it.
Mike
--
Michael David Crawford
mdc@prgmr.com
prgmr.com - We Don't Assume You Are Stupid.
Xen-Powered Virtual Private Servers: http://prgmr.com/xen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Casting 64-bit pointers to integers
2009-05-22 9:30 Casting 64-bit pointers to integers Michael David Crawford
@ 2009-05-22 9:41 ` Samuel Thibault
2009-05-22 9:53 ` Michael David Crawford
0 siblings, 1 reply; 4+ messages in thread
From: Samuel Thibault @ 2009-05-22 9:41 UTC (permalink / raw)
To: Michael David Crawford; +Cc: xen-devel
Michael David Crawford, le Fri 22 May 2009 02:30:35 -0700, a écrit :
> There are typedefs for integers with specific numbers of bits, but
> that's not what we want. If we're building for 32-bit, we want a 32-bit
> integer, and if we're building for 64-bit, we want a 64-bit integer.
intptr_t/uintptr_t is there for this.
Samuel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Casting 64-bit pointers to integers
2009-05-22 9:41 ` Samuel Thibault
@ 2009-05-22 9:53 ` Michael David Crawford
2009-05-22 10:01 ` Samuel Thibault
0 siblings, 1 reply; 4+ messages in thread
From: Michael David Crawford @ 2009-05-22 9:53 UTC (permalink / raw)
To: Michael David Crawford, xen-devel
Samuel Thibault wrote:
> intptr_t/uintptr_t is there for this.
In tools/xenpmd/acpi-events.c, which is in the git sources but doesn't
seem to be in the 3.4 sources, there are two returns from
acpi_events_thread which cast ints to void*'s. These break the compile
on 64-bit.
One of the ints is a socket_fd, the other is the result from a connect
system call.
I got it to compile at first by doing something like this:
return (void*)(unsigned long long)socket_fd
But what would be better is
return (void*)(uintptr_t)socket_fd
If you were to just make socket_fd a uintptr_t, it would lose precision
when you passed it to connect. You could explicitly cast it to an int
there, I suppose.
Mike
--
Michael David Crawford
mdc@prgmr.com
prgmr.com - We Don't Assume You Are Stupid.
Xen-Powered Virtual Private Servers: http://prgmr.com/xen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Casting 64-bit pointers to integers
2009-05-22 9:53 ` Michael David Crawford
@ 2009-05-22 10:01 ` Samuel Thibault
0 siblings, 0 replies; 4+ messages in thread
From: Samuel Thibault @ 2009-05-22 10:01 UTC (permalink / raw)
To: Michael David Crawford; +Cc: xen-devel
Michael David Crawford, le Fri 22 May 2009 02:53:38 -0700, a écrit :
> But what would be better is
>
> return (void*)(uintptr_t)socket_fd
Yes, that's the correct way.
Samuel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-22 10:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-22 9:30 Casting 64-bit pointers to integers Michael David Crawford
2009-05-22 9:41 ` Samuel Thibault
2009-05-22 9:53 ` Michael David Crawford
2009-05-22 10:01 ` Samuel Thibault
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.