Elegant and safe way to determine if architecture is 32bit or 64bit

后端 未结 7 1574
北恋
北恋 2021-01-19 01:47

As title says, is there any elegant and safe way to determine if architecture is 32bit or 64bit. By elegant, you can think of precise, correct, short, clean, and smart way.

7条回答
  •  灰色年华
    2021-01-19 02:14

    If you are using GCC (as indicated in the tags), you can test, as a compile-time test

    #if __SIZEOF_POINTER__ == 8
    

    to find out whether it's a 64-bit system. Make sure the GCC version you are using defines __SIZEOF_POINTER__ at all before using it.

提交回复
热议问题