Subject: Re: Fixing pointer-to-int casts
To: None <lamj@stat.cmu.edu, port-alpha@NetBSD.ORG>
From: Ross Harvey <ross@teraflop.com>
List: port-alpha
Date: 05/16/1998 15:42:16
> What is the best way to fix up the code?  Is there a way to avoid
> sprinkling #ifdef's into the code to differentiate between 32-bit and
> 64-bit platforms, like replacing ints with longs?

Yes, definitely there are some guidelines. I wrote an html document
a month or two ago intended for www.netbsd.org that gives basic
64-bit-clean programming instructions. I'll try to finish that up
some night and make a link off the alpha platform page.

Some quick advice: _never_ use #if's or #ifdef's, there is always
a way to write clean code. A cheap but fairly reasonable fix is to
just change any ints that encapsulate pointers to longs, but it is
usually better to use void * or char * or some_other_type *. Remember
that int is always 32 bits on unix, but long is 32 or 64. There is
a non-standard "long long" in gcc that _might_ be useful.

Do include things like unistd.h, stdlib.h, stdio.y, stddef.h.
Carefully use size_t and ssize_t instead of just "int" for certain
things. In general, try to use use the appropriate prototype headers.
I like to program with the ANSI/ISO C standard and the main Posix
standard open:  they give the `officially'-sanctioned include paths
and entry point for each library function. The netbsd man pages
are a reasonable substitute, however.

Be careful also about the _overuse_ of long. Sometimes it is used to
mean "this must be 32 bits, not 16 bits", possibly by someone who spent
too much time programming for a Mac, 286, or PDP-11. :-)

Ross Harvey