为什么 C 编译器将 long 指定为 32 位,将 long long 指定为 64 位? [英] Why do C compilers specify long to be 32-bit and long long to be 64-bit?

查看:47
本文介绍了为什么 C 编译器将 long 指定为 32 位,将 long long 指定为 64 位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 128 位数字成为现实之前制作 64 位长的数字并保留 long long 不是更有意义吗?

Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality?

推荐答案

是的,确实有道理,但微软有自己的理由将长"定义为 32 位.

Yes, it does make sense, but Microsoft had their own reasons for defining "long" as 32-bits.

据我所知,目前在所有主流系统中,Windows 是唯一一个长"为 32 位的操作系统.在 Unix 和 Linux 上,它是 64 位.

As far as I know, of all the mainstream systems right now, Windows is the only OS where "long" is 32-bits. On Unix and Linux, it's 64-bit.

Windows 的所有编译器都会在 Windows 上将long"编译为 32 位,以保持与 Microsoft 的兼容性.

All compilers for Windows will compile "long" to 32-bits on Windows to maintain compatibility with Microsoft.

因此,我避免使用int"和long".有时我会使用int"来表示错误代码和布尔值(在 C 中),但我从不将它们用于任何依赖于类型大小的代码.

For this reason, I avoid using "int" and "long". Occasionally I'll use "int" for error codes and booleans (in C), but I never use them for any code that is dependent on the size of the type.

这篇关于为什么 C 编译器将 long 指定为 32 位,将 long long 指定为 64 位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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