Best practice in C to support 64-bit or 32-bit address length with same source file ?

Jim McCarthy jkmccarthy at pacbell.net
Sat May 3 19:20:40 UTC 2008


In the thread "RE: Broken dbus" Jay Estabrook wrote:
>> Nyah, what's up Doc?
>
> Same old, same old; doing mostly Opteron, some IA64 Linux for
> clusters these days, mostly kernel support but whatever needs
> doing. Keeping my hand in WRT supporting Alpha Linux as time
> allows.

Jay (or anyone) --

Just recently I've gained access to an HP zx6000 Itanium-2 workstation,
running Scientific Linux for ia64 [a free distro built on RHEL4 sources],
and I have also noticed the recent announcement of FC9 beta for ia64 ... but
it seems there is no "ld -taso" linker option on ia64 Linux :-(meaning the C
source codes I use _will_ require some work, if I want to run on that
platform )-:

As I get into modifying C source code on Alpha Linux to enforce 64-bit
pointer address lengths, rather than have modified source code that _only_
works on 64-bit machines separate from source code that _only_ works on
32-bit machines, it seems preferable to insert branches in the code as
needed to support either architecture (certainly this is NOT a new/original
idea :-).  But what is the proper compiler -D<flag> to test against that
would also work identically on ia64 Linux ?  Granted I'm free (I think) to
invent a flag with any name I choose, but is there a widely-used convention
I should follow ?

Namely, what is the commonly accepted "best practice" for branching in C
code using

> #ifdef _______
>    ...treat address pointers as 64-bit...
> #else
>    ...treat address pointers as 32-bit...
> #endif

that would work most transparently on Alpha Linux _and_ ia64 Linux ?  (i.e.,
what -D<flag> should I test against at "______" above ?)  Or is it better to
insert C code that branches (during execution?) based on some test involving
sizeof( ) ... or maybe instead use sizeof( ) somehow in declarations so any
integers equated to address pointers get declared appropriately for either
32-bit or 64-bit architectures ?

I'd appreciate any expert opinions and/or code fragment examples of how best
to implement this (given the myriad of possibilities a novice in my position
might come up with ...).

Thanks,

     -- Jim


-----Original Message-----
From: Jim McCarthy
Sent: Tuesday, April 22, 2008 11:23 PM
To: axp-list at redhat.com
Subject: FC 8 on Alpha question: GNU linker "ld -taso" option?

<snip>

Arguably this would be "good medicine" and motivation to properly upgrade
the IA32 data analysis package's source codes to allow (enforce) 64-bit
pointers on all 64-bit architectures (Alpha, ia64 = Itanium, AMD64, EM64T,
etc.) -- a very sizeable effort [somewhere between "daunting" and
"monumental" for me by myself] but one that would no doubt pay future
dividends....  Still, I'd appreciate knowing if in the meantime the new FC 8
on Alpha might have the "-taso" shortcut I could use to get up-and-running
quickly after upgrading from RH7.2 Alpha.

Thanks,

     -- Jim
_________________________________________
axp-list mailing list
axp-list at redhat.com
https://www.redhat.com/mailman/listinfo/axp-list




More information about the axp-list mailing list