开发者

long for 12 digit number?

开发者 https://www.devze.com 2023-03-14 11:21 出处:网络
I\'m trying to use long for 12 digit number but it\'s saying \"integer constant is too large for \"long\" type\", and I tried it with C++ and Processing (similar to Java).What\'s happening and what sh

I'm trying to use long for 12 digit number but it's saying "integer constant is too large for "long" type", and I tried it with C++ and Processing (similar to Java). What's happening and what should I use fo开发者_Python百科r it?


In C and C++ (unlike in Java), the size of long is implementation-defined. Sometimes it's 64 bits, sometimes it's 32. In the latter case, you only have enough room for 9 decimal digits.

To guarantee 64 bits, you can use either the long long type, or a fixed-width type like int64_t.


If you are specifying a literal constant, you must use the appropriate type specifier:

int i = 5;
unsigned i = 6U;

long int i = 12L;
unsigned long int i = 13UL;

long long int i = 143LL;
unsigned long long int i = 144ULL;

long double q = 0.33L;

wchar_t a = L'a';


I don't know in C++, but in C, there is a header file called <stdint.h> that will portably have the integer types with the number of bits you desire.

int8_t 
int16_t
int32_t
int64_t

and their unsigned counterpart (uint8_t and etc).

Update: the header is called <cstdint> in C++


Try using a long long in gcc or __int64 in msvc.

0

精彩评论

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