Re: int vs void *

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 07/09/04


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


Relevant Pages

  • Re: int vs void *
    ... > between type int and void *, on roughly how many different kinds of machines ... On almost all machines where void * isn't 32 bits. ... Use a pointer when you pointer, ...
    (comp.lang.c)
  • int vs void *
    ... Using casts ... between type int and void *, on roughly how many different kinds of machines ...
    (comp.lang.c)
  • Re: int vs void *
    ... Using casts ... > between type int and void *, on roughly how many different kinds of ... > i'm wondering how portable it is to write code that treats int and void * ...
    (comp.lang.c)
  • Re: int vs void *
    ... > between type int and void *, on roughly how many different kinds of ... > machines would it not work? ... Don't write nonportable code as long as an alternative exists. ...
    (comp.lang.c)
  • Re: resolving a warning error
    ... >> compatible with type int? ... compatible are described in 6.7.2 for type specifiers, ... and in 6.7.5 for declarators. ... Dan Pop ...
    (comp.lang.c)