From owner-freebsd-current@FreeBSD.ORG Sun Sep 9 17:52:37 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 391AD16A417 for ; Sun, 9 Sep 2007 17:52:37 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (xorpc.icir.org [192.150.187.68]) by mx1.freebsd.org (Postfix) with ESMTP id 189E113C4B0 for ; Sun, 9 Sep 2007 17:52:37 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (localhost [127.0.0.1]) by xorpc.icir.org (8.12.11/8.13.6) with ESMTP id l89HpK6w035749; Sun, 9 Sep 2007 10:51:20 -0700 (PDT) (envelope-from rizzo@xorpc.icir.org) Received: (from rizzo@localhost) by xorpc.icir.org (8.12.11/8.12.3/Submit) id l89HpKRv035748; Sun, 9 Sep 2007 10:51:20 -0700 (PDT) (envelope-from rizzo) Date: Sun, 9 Sep 2007 10:51:20 -0700 From: Luigi Rizzo To: "M. Warner Losh" Message-ID: <20070909105120.B34897@xorpc.icir.org> References: <20070906111028.A83649@xorpc.icir.org> <20070909.111845.-861032475.imp@bsdimp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20070909.111845.-861032475.imp@bsdimp.com>; from imp@bsdimp.com on Sun, Sep 09, 2007 at 11:18:45AM -0600 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: Sun, 09 Sep 2007 17:52:37 -0000 On Sun, Sep 09, 2007 at 11:18:45AM -0600, M. Warner Losh wrote: > In message: <20070906111028.A83649@xorpc.icir.org> > Luigi Rizzo writes: > : 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). > > It is portable. gcc, and other compilers, define this when using > longs and pointers as 64 bit. There's also ILP32 and ILP64 > programming models, but only windows 64 uses the latter. > > Typically, however, there are better ways to solve problems relating > to these differences. What kinds of problems are you trying to solve? i need to do this: #ifdef BUILT_FOR_64BIT_POINTERS #define MY_MAGIC 0xdeadbeefd00de123 /* 64 bit */ #else #define MY_MAGIC 0xdeadbeef /* 32 bit */ If you know of a way to implement this without preprocessor magic, i am all ears. If the values were simpler (eg all ones or so) i could have used ~((unitptr_t)0) but this is not the case here If there is no better way i can do this static __unused char __invalid_pointer[] = "This is an invalid pointer"; #define MY_MAGIC ((void *)__invalid_pointer) and be done with it. cheers luigi