gcc,不同架构上 long int 的宽度 [英] gcc, width of long int on different architectures
问题描述
在 64 位架构上,long int
,根据 gcc 至少是一个 int64_t
.在 32 位上,long int
至少是 int32_t
.对于 Microsoft 编译器,long
始终是 int32_t
,无论是 32/64 位.有什么办法可以:
On 64-bit architectures, long int
, according to gcc is at least an int64_t
. On 32-bit, long int
is at least int32_t
. With Microsoft compilers, long
is always an int32_t
, regardless of 32/64-bit. Is there any way to:
- 强制 gcc 在 32 位上将 long 视为 int64_t?(为了便于测试)
- 强制 gcc 在 64 位上将 long 视为 int32_t?(为了符合 MS 的编译器).
推荐答案
不要这样做 - 使用标准类型,例如 int32_t
、uint32_t
、int64_t
、uint64_t
等来自
而不是试图对诸如 long int
或试图让编译器按你的意愿行事.
Don't do this - use standard types such as int32_t
, uint32_t
, int64_t
, uint64_t
, etc from <stdint.h>
rather than trying to make assumptions about naked types such as long int
or trying to bend the compiler to your will.
注意:任何给定平台的 64 位模型(例如大多数 *nix 平台的 LP64、Mac OS X 等)是给定的,因此即使您可以说服编译器使用不同的 64 位模型可能会中断对系统代码、库等的任何调用.
Note: The 64-bit model for any given platform (e.g. LP64 for most *nix platforms, Mac OS X, etc) is a given, so even if you could convince the compiler to use a different 64-bit model you would probably break any calls to system code, libraries, etc.
这篇关于gcc,不同架构上 long int 的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!