From owner-freebsd-current@FreeBSD.ORG Fri Sep 7 11:51:15 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 890E216A421 for ; Fri, 7 Sep 2007 11:51:15 +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 09B6913C48A for ; Fri, 7 Sep 2007 11:51:14 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile.ondsl.gr [83.235.244.135]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-8) with ESMTP id l87Bog78021844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 7 Sep 2007 14:51:03 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id l87BoN5g002793; Fri, 7 Sep 2007 14:50:39 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id l87BoMcH002792; Fri, 7 Sep 2007 14:50:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Fri, 7 Sep 2007 14:50:21 +0300 From: Giorgos Keramidas To: Luigi Rizzo Message-ID: <20070907115021.GA2718@kobe.laptop> References: <20070906111028.A83649@xorpc.icir.org> <20070906222647.GB2737@kobe.laptop> <20070907000950.A91211@xorpc.icir.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070907000950.A91211@xorpc.icir.org> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.96, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.44, 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: Fri, 07 Sep 2007 11:51:15 -0000 On 2007-09-07 00:09, Luigi Rizzo wrote: >On Fri, Sep 07, 2007 at 01:26:47AM +0300, Giorgos Keramidas wrote: >>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. > > i am actually looking at pointer sizes, as i need to do some pointer > manipulation going through intptr_t, and need to know that in the > preprocessor because some constants need to be 32 or 64 bit depending > on that, and are not trivial (i.e. not 0, 1 or something i can build > with size-agnostic expressions) An intptr_t can safely hold any void pointer value, and C99 says: % 7.18.1.4 Integer types capable of holding object pointers % % 1 The following type designates a signed integer type with the % property that any valid pointer to void can be converted to % this type, then converted back to pointer to void, and the % result will compare equal to the original pointer: % % intptr_t What sort of manipulation? Can this sort of manipulation be written in a way that uses sizeof(intptr_t) instead of 4, 8, or preprocessor magic? If not, then I can't think of any cross-compiler and cross-platform way to check in the preprocessor, and you may have to resort to custom checks (i.e. like those written in autoconf scripts) :-( - Giorgos