开发者

"long int", "long long" Data Types

What is the purpose of these new data types? I will normally just use an "int" or a "long" b开发者_如何学Cut why do these exist? What new function or purpose do they bring?


long int has always been the full name of long, just rarely used.

long long has been around for a while (in last C standard), and guarantees at least 64bit size (long only guarantees 32bits).


Well, they bring a larger range of integers so computers can easily handle, for example, Bill Gates' tax returns.

As an aside, long int isn't very new at all but most people just use the shorter variant long.

Look for the sequels to these in an upcoming draft of the new ISO standards:

longer long      - slightly larger than a long long (this was initially put
                   forward as "long long long" but the ISO committee barfed).
even longer long - bigger yet.
stupendous long  - should keep us going for a while.

</humour>


Well, obviously a "long long" is even longer than a "long". :)

The difference is platform-specific: "long long" can be a 64-bit integer when "long" is 32-bit or they may both be 64-bit. As for "long int", that's just the long way of saying "long", no pun intended.


Probably to bring C++ into line with C99 which supports it (and to bring the standard into line with what compilers actually support, since most of them already supported long long).


long int is just the full form of long, and is distinct from, for example unsigned long int and so on. This is not new in C++0x.

long long is common in compilers already today; for compatibility, it is conventional that both long and int are 32 bits even on 64-bit architectures; long long specifies 64-bits in such circumstances; its part of C99 and must be at least 64-bits as per that standard.

You can also get 128-bit data-types on some compilers using long long long; other compilers provide such numbers using attributes (GCC has __attribute__((__mode__(__TI__)))), for example) and most have a <limits.h> that has an __int128_t/__uint128_t.


As mentioned these types are not new. You might be interested in this overview. As an additional remark, if confused about types, you could also use intn_t types which have a more clearer "meaning".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜