Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Paul Tomblin <ptomblin@xcski.com>
To: axp-list@redhat.com
Subject: Re: Making programs 64 bit clean
Date: Mon, 22 Jun 1998 14:09:40 -0400	[thread overview]
Message-ID: <19980622140940.A4564@xcski.com> (raw)
In-Reply-To: <Pine.LNX.3.96.980622112328.5028A-100000@rnaworld.princeton.edu>; from Tim Jenkins on Mon, Jun 22, 1998 at 11:36:05AM -0400

Quoting Tim Jenkins (tim@rnaworld.princeton.edu):
> 
> I have several programs which cast pointers to ints, which I am hoping to
> clean up.  It appears that if I redefine the integer variables as longs
> and then cast the pointers to longs, I am converting a 64 bit pointer to a
> 64 bit long, rather than a 64 bit pointer to a 32 bit int. 
> e.g.

According to (my memory of) the ANSI standard, converting from a pointer to an
int is not safe.  Period.  If you want to be safe (i.e portable), use a void*
as your data type to store pointers, not ints or longs.  One way to do this
would be

typedef union int_or_ptr
{
    long    intval;
    void*   ptrval;
} int_or_ptr_t;

int_or_ptr_t var;

var.ptrval = some_pointer;
or
var.intval = 12;

It would then be up to you to make sure you only used var.ptrval when you'd
stored a pointer then, and use var.intval when you'd stored one of the
integral data types.

-- 
Paul Tomblin, ptomblin@xcski.com.
"The day Microsoft makes something that doesn't suck is probably the day they
start making vacuum cleaners" - Ernst Jan Plugge


  reply	other threads:[~1998-06-22 18:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-22 15:36 Making programs 64 bit clean Tim Jenkins
1998-06-22 18:09 ` Paul Tomblin [this message]
1998-06-22 19:27 ` Christopher Curtis
  -- strict thread matches above, loose matches on Subject: below --
1998-06-22 17:35 Greg Lindahl
1998-06-22 19:32 ` Michal Jaegermann
1998-06-22 20:47   ` Christopher Curtis
1998-06-22 21:49     ` Michal Jaegermann
1998-06-22 21:50     ` Paul Tomblin
1998-06-22 22:24       ` Jeff Sturm
1998-06-22 19:53 ` Richard Hadsell
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox