[flac-dev] How to check for 64-bit CPU?

Erik de Castro Lopo mle+la at mega-nerd.com
Mon Dec 28 23:08:48 PST 2015


lvqcl wrote:

> A) How to properly check for 64-bit architectures?
> I can check for "defined FLAC__CPU_X86_64" or "defined _WIN64".

Eww :)

> Is it possible to use SIZEOF_VOIDP? such as "#if SIZEOF_VOIDP == 8" ?

That would work.
 
> B) Does it make sense to put the following code into some header file?
> (if yes, what header file should be used?)
> 
> 
>   #if (defined FLAC__CPU_X86_64) || ...something else here...
>   #define FLAC__64BIT_ARCH 1
>   #else
>   #undef FLAC__64BIT_ARCH
>   #endif

I would suggest:

   #if SIZEOF_VOIDP == 8
   #define FLAC__64BIT_ARCH 1
   #else
   #define FLAC__64BIT_ARCH 0
   #endif

Setting a #define to either `0` or `1` means that it can be used in code like

   if (FLAC__64BIT_ARCH) {
       // 64 bit code
   } else {
       // 32 bit code
   }

and the compiler will syntax/type check both branches but optimises one
away completely.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the flac-dev mailing list