我应该使用long long或为的int64_t便携式code? [英] Should I use long long or int64_t for portable code?
问题描述
我有一个是写在C和C ++的开放源代码codeBase的。我在寻找这是保证是一个整数类型的至少的64位宽,可与开源的C可靠地编上最OS X(英特尔64位)和Linux系统和C ++编译器,而对最终用户的部分太多额外的工作。 Windows和32位客户端的支持并不重要,在这个时候。
I have an open-source codebase that is written in both C and C++. I'm looking for an integer type that is guaranteed to be at least 64 bits wide, which can be reliably compiled on most OS X (Intel, 64-bit) and Linux boxes with open-source C and C++ compilers, without too much extra work on the end user's part. Windows and 32-bit client support are not important at this time.
我没有在OS X上一些测试,并附带的开发工具不支持C + 11模式(因此似乎并不保证长长$ C可用性的最新GCC $ C>)。锵不支持此项工作,要么,虽然它支持
长长
如果启用C99模式,经过一定的版本。
I did some testing on OS X, and the latest GCC that ships with the developer tools does not support C+11 mode (and therefore does not seem to guarantee availability of long long
). Clang does not support this, either, though it supports long long
if C99 mode is enabled, after a certain version.
时,一般建议使用的int64_t
代替长长
,当便携性是一个重要的目标是什么?使用格式说明似乎痛苦。
Is the general suggestion to use int64_t
in place of long long
, when portability is an important goal? Using the format specifiers seems painful.
我可以可靠地投了的int64_t
到长长
(以及同样的符号
等效采用 uint64_t中
)以与利用现有功能和库使用长长
作为参数? (和回来的,当然。)
Can I reliably cast an int64_t
to long long
(and likewise to the unsigned
equivalent with uint64_t
) to use it with existing functions and libraries that take long long
as parameters? (And back again, of course.)
在那种心境下,如果我船code,需要锵功能不是在GCC,是锵将会取代GCC作为首选的Linux上的编译器?提供源$ C $ C给最终用户时,是什么编译器,我可以预料,在大多数情况下,?
In that frame of mind, if I ship code that requires Clang functionality not in GCC, is Clang going to replace GCC as the compiler of choice on Linux? Is that compiler something I can expect, for the most part, when offering source code to end users?
基本上,我想问问从谁使用这两种类型的便携式C和C ++ code其他开发商,谁可能有什么可能是更好的长期的路要走一些建议,一些建议,鉴于上述目标的记在心里。
Basically, I'd like to ask for some advice from other developers who have used both types for portable C and C++ code, who might have some suggestions on what might be the better long-term way to go, given the above goal in mind.
推荐答案
类型长长
和无符号长长
是标准C和标准C ++类型与至少64位。所有的编译器我知道提供这些类型的,可能除了当在 -pedantic
模式,但在这种情况下,的int64_t
或 uint64_t中
将是不可用的pre-C ++编译器2011,无论是。在所有的系统< stdint.h>
是可用的,太。也就是说,只要我可以告诉它并没有多大关系如何拼写的类型。 1所述的主要目标; stdint.h>
是为特定比特数提供最佳匹配。如果你需要至少64位,但你也想采取禁食实施这一类型的优势,你会使用 int_least64_t
或 uint_least64_t
从< stdint.h>
或< cstdint>
(在后一种情况下, ,该名在命名空间中定义 STD
)。
The types long long
and unsigned long long
are standard C and standard C++ types each with at least 64 bits. All compilers I'm aware of provide these types, except possibly when in a -pedantic
mode but in this case int64_t
or uint64_t
won't be available with pre-C++ 2011 compilers, either. On all of the systems <stdint.h>
is available, too. That is, as far as I can tell it doesn't matter much how you spell the type. The main goal of <stdint.h>
is to provide the best match for a specific number of bits. If you need at least 64 bit but you also want to take advantage of the fasted implementation of such a type, you'd use int_least64_t
or uint_least64_t
from <stdint.h>
or <cstdint>
(in case of the latter, the names are defined in namespace std
).
这篇关于我应该使用long long或为的int64_t便携式code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!