From owner-freebsd-current@FreeBSD.ORG Thu Sep 6 22:46:04 2007 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6601F16A41A for ; Thu, 6 Sep 2007 22:46:04 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id A27C513C481 for ; Thu, 6 Sep 2007 22:46:03 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (dialup148.ach.sch.gr [81.186.70.148]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-8) with ESMTP id l86MRC5V012188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 7 Sep 2007 01:27:21 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id l86MQueu003184; Fri, 7 Sep 2007 01:26:58 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id l86MQm7d003176; Fri, 7 Sep 2007 01:26:48 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Fri, 7 Sep 2007 01:26:47 +0300 From: Giorgos Keramidas To: Luigi Rizzo Message-ID: <20070906222647.GB2737@kobe.laptop> References: <20070906111028.A83649@xorpc.icir.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070906111028.A83649@xorpc.icir.org> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.872, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.53, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: current@freebsd.org Subject: Re: how to tell 64 vs 32 bit architecture ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Sep 2007 22:46:04 -0000 On 2007-09-06 11:10, Luigi Rizzo 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