Re: int vs void *
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 07/09/04
- Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: gcc compiler"
- Previous message: Dan Pop: "Re: Cursor libraries"
- In reply to: ChokSheak Lau: "int vs void *"
- Next in thread: Darrell Grainger: "Re: int vs void *"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Jul 2004 14:05:59 GMT
In <ccluue$527$1@news-int.gatech.edu> "ChokSheak Lau" <choksheak@yahoo.com> writes:
>hi, this should be more of a systems compatibility question. Using casts
>between type int and void *, on roughly how many different kinds of machines
>would it not work? means do you know of any machine in which sizeof(int) !=
>sizeof(void *)?
Yup, most 64-bit Unix systems use the I32LP64 model, which is incompatible
with your assumption. It didn't work in the days of MS-DOS, either, for
certain memory models: large, huge, compact.
>i'm wondering how portable it is to write code that treats int and void * in
>the interchangeably. apparently gcc used to do that, but i'm not sure that
>had changed that or not.
If you need to convert a pointer to an integer type, use unsigned long
instead of int. Or uintptr_t on C99 compilers. No universal guarantee
that it will work, but your chances are MUCH better than with type int.
Dan
-- Dan Pop DESY Zeuthen, RZ group Email: Dan.Pop@ifh.de
- Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: gcc compiler"
- Previous message: Dan Pop: "Re: Cursor libraries"
- In reply to: ChokSheak Lau: "int vs void *"
- Next in thread: Darrell Grainger: "Re: int vs void *"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|