integer constant long long int?
long 开发者_运维问答long int
It seems to be valid in C. but is this valid in c++?
The data type long long int
is valid only in the C99 and C++0x language standards, it is not valid in C90 or C++03. Some compilers such as GCC permit it to be used in those earlier language versions as an extension—when compiling as C90. GCC will give a warning on its usage if both the -Wlong-long
and -pedantic
options are specified.
It's in the C++0x standard. This answers your question: http://en.wikipedia.org/wiki/Long_integer
Please keep in mind that like all other primitive types in C and C++, only the ranges for the values the primitives may contain are well-defined; the actual size of the primitive, in bits, is left up to the implementation. I have not had much experience using long long int
, since I prefer using the types defined in the stdint.h
header. If you need to be sure that the primitive is, for example, 64 bits long, you may want to consider using uint64_t
or int64_t
instead.
It's not portable in C++. What is normally done in programs is to have a single .h file that defines all the numeric types you are going to need depending on compiler/hw. For example you may find code like
#if defined(__THISCOMPILER__)
typedef long long int64;
typedef unsigned long long uint64;
typedef short int16;
typedef unsigned short uint16;
...
#elseif defined(__THATCOMPILER__)
typedef __int64 int64;
...
#endif
then in the rest of the code only types like int64
are used instead of the specific compiler-dependent declarations to keep most of the source portable.
C99 defined standard names for types of a specific size (or of a minimum guaranteed size) but not every compiler out there is fully C99 compliant so this kind of typedef include is still quite common. Note also that currrent standard C++ doesn't include C99.
精彩评论