Messages in this thread | | | From | "H. Peter Anvin" <> | Subject | Re: Q: void* vs. unsigned long | Date | Mon, 15 Feb 1999 21:43:39 -0800 (PST) |
| |
> On 16 Feb 1999, H. Peter Anvin wrote: > > > > sizeof (void *) == sizeof (unsigned long) if and only if you are on a > > > 32-bit arch, like i386. > > > > Actually, it will. sizeof(unsigned long) == sizeof(void *) == 8 on > > 64-bit architectures. > > And probably a couple 16-bit systems as well. But that's just > coincidence. For instance, if the 386 wasn't so woefully register-impaired, > unsigned long would be 64-bit. And I'd bet a quarter that sizeof(void *) > will not be 16 on a 128-bit machine (when we finally see one). > > But what we need here is "an integral type which can represent all > possible pointer values". Unsigned long should be safe for that on all > sane architectures/compilers[1] and might even be guaranteed by the C > standard. Probably won't work on all DSPs though, but we're not likely to > see any of those running Linux soon for other reasons. >
I've personally been fond of poi_t (pointer or integer _t):
typedef union { void *p; signed long s; unsigned long u; } poi_t;
... or the respective. Of course, if one doesn't like unions, one can do the same thing as a typedef to the integral type.
-hpa
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |