Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Sep 2007 01:26:47 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Luigi Rizzo <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: how to tell 64 vs 32 bit architecture ?
Message-ID:  <20070906222647.GB2737@kobe.laptop>
In-Reply-To: <20070906111028.A83649@xorpc.icir.org>
References:  <20070906111028.A83649@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2007-09-06 11:10, Luigi Rizzo <rizzo@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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070906222647.GB2737>