how to tell 64 vs 32 bit architecture ?
Luigi Rizzo
rizzo at icir.org
Sun Sep 9 10:52:37 PDT 2007
On Sun, Sep 09, 2007 at 11:18:45AM -0600, M. Warner Losh wrote:
> In message: <20070906111028.A83649 at xorpc.icir.org>
> Luigi Rizzo <rizzo at icir.org> 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
More information about the freebsd-current
mailing list