Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Making programs 64 bit clean
@ 1998-06-22 15:36 Tim Jenkins
  1998-06-22 18:09 ` Paul Tomblin
  1998-06-22 19:27 ` Christopher Curtis
  0 siblings, 2 replies; 10+ messages in thread
From: Tim Jenkins @ 1998-06-22 15:36 UTC (permalink / raw)
  To: axp-list


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.

Unacceptable:

int foo;
int *bar;

foo = (int) bar;

Acceptable?:

long foo;
int *bar;

foo = (long) bar;


Is this an acceptable solution to making programs 64 bit clean and is it
portable across 32 bit and 64 bit platforms? 

thanks,

tim



^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Making programs 64 bit clean
@ 1998-06-22 17:35 Greg Lindahl
  1998-06-22 19:32 ` Michal Jaegermann
  1998-06-22 19:53 ` Richard Hadsell
  0 siblings, 2 replies; 10+ messages in thread
From: Greg Lindahl @ 1998-06-22 17:35 UTC (permalink / raw)
  To: axp-list

> Unacceptable:
> 
> int foo;
> int *bar;
> 
> foo = (int) bar;
> 
> Acceptable?:
> 
> long foo;
> int *bar;
> 
> foo = (long) bar;
> 
> 
> Is this an acceptable solution to making programs 64 bit clean and is it
> portable across 32 bit and 64 bit platforms? 

This is the easiest way to fix broken code. However, it isn't
necessarily portable to other 64 bit machines -- I think everyone
else (?) defines long == 32 bits and long long == 64 bits.

Your best bet for a clean, easy solution is to typedef an int64 type
and use that, with an appropriate definition for each machine. If you
are clever you can put that into a configure script...

It's much better in the long run to fix the programs to not cast
pointers to ints of any width, but of course that is much more
expensive than this quick hack.

-- g





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1998-06-22 22:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-06-22 15:36 Making programs 64 bit clean Tim Jenkins
1998-06-22 18:09 ` Paul Tomblin
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

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