开发者

what is long long type? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

“long int”, “long long” Data Types

开发者_JAVA技巧

I am a newbie of C++ and I looked at a sample code and I saw long long type. It says something like this

long long deviceId;

Is this same as long type? I am trying to send a device id from java(Android) to my server. In java, device id is long type(8byte) and I am putting this into the buffer like

bytebuffer.putLong(Long.valueOf(deviceId));

I am trying to parse this on my linux server using c++.

Thanks in advance.


long long is not the same as long (although they can have the same size, e.g. in most 64-bit POSIX system). It is just guaranteed that a long long is at least as long as a long. In most platforms, a long long represents a 64-bit signed integer type.

You could use long long to store the 8-byte value safely in most conventional platforms, but it's better to use int64_t/int_least64_t from <stdint.h>/<cstdint> to clarify that you want an integer type having ≥64-bit.

#include <stdint.h>
...
int64_t deviceId;


http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html

ISO C99 supports data types for integers that are at least 64 bits wide, and as an extension GCC supports them in C90 mode and in C++. Simply write long long int for a signed integer, or unsigned long long int for an unsigned integer. To make an integer constant of type long long int, add the suffix LL' to the integer. To make an integer constant of type unsigned long long int, add the suffixULL' to the integer.


C99 and C++0x differ on the meaning of long long int. (There is no long long int in C++ 2003, although many vendors do supply it.) C99 is very specific: long long int is at least 64 bits. C++0x is incredibly vague: sizeof(long long int) >= sizeof(long int) >= sizeof(int) >= sizeof(short int) >= sizeof(signed char). The only one with special meaning is int, which is the most natural size for the execution environment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜