From owner-freebsd-current@FreeBSD.ORG Fri Sep 7 13:54:38 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 6DC4516A41A for ; Fri, 7 Sep 2007 13:54:38 +0000 (UTC) (envelope-from rottled@gmail.com) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.185]) by mx1.freebsd.org (Postfix) with ESMTP id B93F913C48D for ; Fri, 7 Sep 2007 13:54:36 +0000 (UTC) (envelope-from rottled@gmail.com) Received: by nf-out-0910.google.com with SMTP id k4so389357nfd for ; Fri, 07 Sep 2007 06:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=HZmEXrhmDEN6ERMx6mMwZwEDbtIYWQhSVpsd9CBhPUk=; b=fP6PL3b/CgH/SsV82w4FUlsN+jPbN5oEmOiPcY4BpJqciEpFKe9MbWvlp0vTNI1ZewwFZuKsn2ZkxhgOqgaJx43lrVKSIQH5fZwv2D+w9PWhfCNqg5cMUbNiyowhTyioN2P4TR3oN0EuxaIkTZl70fTOu98yllBcfozQHggl9JU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Sd1SKhzwCOpCC3EbaqBg6+9ABmCiLbC0Y5KyrbvK2v+wKGNzWJm0CKh1AR1g/N7pbyiFesbSR6DEguNBIzMV/rTCNHRHb9Z/20OWbwQbd6Iy+ejsS6gxKt1HduY2e2LH2WnhYIGhH5nU+cTUBoibYwXxK2wY2dXqkg7lKq5kw8I= Received: by 10.86.51.2 with SMTP id y2mr1454996fgy.1189173275554; Fri, 07 Sep 2007 06:54:35 -0700 (PDT) Received: by 10.86.25.18 with HTTP; Fri, 7 Sep 2007 06:54:35 -0700 (PDT) Message-ID: <54b90fdf0709070654h103316f3sa3d423f4ff75fee3@mail.gmail.com> Date: Fri, 7 Sep 2007 09:54:35 -0400 From: Yan To: "Luigi Rizzo" In-Reply-To: <20070907050310.A94579@xorpc.icir.org> MIME-Version: 1.0 References: <20070906111028.A83649@xorpc.icir.org> <20070906222647.GB2737@kobe.laptop> <20070907000950.A91211@xorpc.icir.org> <20070907115021.GA2718@kobe.laptop> <20070907050310.A94579@xorpc.icir.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 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 13:54:38 -0000 How about this: #define MY_MAGIC ((sizeof(intptr_t)==4) ? 0Xdeadbeef : 0xdeadbeefd00de123) You can also test it via 'if(sizeof(intptr_t)&0x4)'. This is assuming you won't run this on a 16 bit architecture :p -yan On 9/7/07, Luigi Rizzo wrote: > > On Fri, Sep 07, 2007 at 02:50:21PM +0300, Giorgos Keramidas wrote: > > 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? > > 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 > > cheers > luigi > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >