如何检测编译是32位还是64位? [英] how to detect the compile is 32 bits or 64 bits?

查看:170
本文介绍了如何检测编译是32位还是64位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测源代码中的编译是32位还是64位代码本身。所以不同的代码分别编译。怎么办

这个?

i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?

推荐答案

steve yee写道:
steve yee wrote:

i想要检测源代码中的编译是32位还是64位

代码本身。所以不同的代码分别编译。怎么办

这个?
i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?



没有便携方式。


有*便携式方法来检查算术范围

类型在编译时,如果那是你的不同代码需要。

使用< limits.hheader中定义的宏。


-

Eric Sosman
es*****@acm-dot-org.inva


steve yee发布:
steve yee posted:

i想要检测源代码中的编译是32位还是64位

代码本身。所以不同的代码分别编译。怎么办

这个?
i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?



如果您正在编写可移植代码,则不需要。


尽管如此,您可以尝试一些东西喜欢:


#include< limits.h>


/ * inttype_MAX或任何(1<<< k)-1,其中0 <= k <1。 3.2E + 10

* /

#define IMAX_BITS(m)((m)/((m)%0x3fffffffL + 1)/ 0x3fffffffL%0x3fffffffL *

30 \

+(m)%0x3fffffffL /((m)%31 + 1)/ 31%31 * 5 + 4-12 /((m)%31 + 3))


#if IMAX_BITS(UINT_MAX)== 32

#define BIT32

#else

#if IMAX_BITS(UINT_MAX)== 64

#define BIT64

#else

#error"系统必须是32 -Bit或64-bit。"

#endif

#endif


int main(无效)

{

/ *这是我的非便携代码* /

}


-


Frederick Gotham


You shouldn''t need to if you''re writing portable code.

Nonetheless, you could try something like:

#include <limits.h>

/* Number of bits in inttype_MAX, or in any (1<<k)-1 where 0 <= k < 3.2E+10
*/
#define IMAX_BITS(m) ((m) /((m)%0x3fffffffL+1) /0x3fffffffL %0x3fffffffL *
30 \
+ (m)%0x3fffffffL /((m)%31+1)/31%31*5 + 4-12/((m)%31+3))

#if IMAX_BITS(UINT_MAX) == 32
#define BIT32
#else
#if IMAX_BITS(UINT_MAX) == 64
#define BIT64
#else
#error "System must be either 32-Bit or 64-Bit."
#endif
#endif

int main(void)
{
/* Here''s my non-portable code */
}

--

Frederick Gotham


steve yee写道:
steve yee wrote:

i想要在源代码中检测编译是32位还是64位

代码本身。所以不同的代码分别编译。怎么办

这个?
i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?



你邀请bug,以及关于
$ b $主题的问题b标准C,如果你编写了必须改变的源代码。通常的

问题是关于(sizeof)<各种指针类型>。如果您的问题仅仅是(sizeof)int,那么您可以通过假设它是否具有32位或64位平台来确定问题来创建问题。如果你坚持使用指针和整数联盟的
,知道它是32位还是64位

不会拯救你。更重要的是,如果你是编写代码的人之一,那么

取决于(sizeof)(size_t x)。

You invite bugs, as well as taking the question off the topic of
standard C, if you write source code which has to change. The usual
question is about (sizeof)<various pointer types>. If your question is
simply about (sizeof)int, you create problems by assuming it is
determined by whether you have a 32- or 64-bit platform. If you insist
on unions of pointers and ints, knowing whether it is 32 or 64 bits
won''t save you. More so, if you are one of those who writes code which
depends on (sizeof)(size_t x).


这篇关于如何检测编译是32位还是64位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆