Re: how to tell 64 vs 32 bit architecture ?

From: Giorgos Keramidas <keramida_at_ceid.upatras.gr>
Date: Fri, 7 Sep 2007 01:26:47 +0300
On 2007-09-06 11:10, Luigi Rizzo <rizzo_at_icir.org> wrote:
> hi,
> i was wondering what is the proper way to tell a 64 vs 32 bit
> architecture.
>
> I see that some code in sys/ uses  ' #ifdef __LP64__ ' but i am not
> sure if this is generic enough (ie not gcc or FreeBSD specific),
> and also suitable for userland (i.e. works on linux or other platforms
> as well).

This is usually needed to differentiate between a feature "X" which
behaves differently in amd64 vs. i386 vs. sparc vs. sparc64, etc.

If this is for userland-code, why can't you test directly for #ifdef
HAVE_FEATURE_X (sorry for the autotools/GNU'ism there)?  It's safer this
way in the long term, because if one of teh architectures which
currently lack "feature X" grows support for it, you won't get bitten
down the road by the wrong assumption in one of the "#ifdef AMD64"
checks in the source.

I'm not really suggesting that it is completely wrong to check for
the system architecture in general, but I have seen very few use
cases for this at ${realjob} at the C preprocessor level.  Almost
every time someone used "#ifdef __solaris__" or something like
"#ifdef __amd64__" it became a pain to debug later when, for example,
we upgraded our compiler suite or something :-(

- Giorgos
Received on Thu Sep 06 2007 - 20:46:04 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:17 UTC