海湾合作委员会,宽长整型不同架构 [英] gcc, width of long int on different architectures

查看:171
本文介绍了海湾合作委员会,宽长整型不同架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在64位架构,长整型,根据GCC是至少的int64_t 。在32位,长整型至少 int32_t 。随着微软的编译器,始终是一个 int32_t ,不论32/64位。有没有什么办法:

  1. 强制GCC对待只要一个的int64_t,在32位? (为便于测试)
  2. 强制GCC治疗,只要在64位一个int32_t? (是否符合MS的编译器)。
解决方案

不这样做 - 使用标准类型,如 int32_t uint32_t的的int64_t uint64_t中等从< stdint。 H> ,而不是试图做出赤裸裸的类型,如长整型或试图弯曲编译你的意愿假设

注:64位模式对于任何给定的平台(例如,LP64大多数* nix平台,Mac OS X的,等等)是给定的,因此,即使你能说服编译器使用不同的64位模式,你可能会打破任何调用系统code,图书馆等。

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:

  1. Force gcc to treat long as a int64_t, on 32bit? (for ease of testing)
  2. Force gcc to treat long as a int32_t on 64bit? (for compliance with MS's compiler).

解决方案

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.

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.

这篇关于海湾合作委员会,宽长整型不同架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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