tags:

views:

205

answers:

6

Hi, What is the purpose of these new data types? I will normally just use an "int" or a "long" but why do these exist? What new function or purpose do they bring?

+5  A: 

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).

Richard
A: 

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>

paxdiablo
You missed off long++
amelvin
Going the other way, there's an opportunity to realize a `short long`. This has the advantage of introducing no new keywords. They could also introduce a `short short` as a way of doing a guaranteed byte-length quantity, freeing up `char` to be whatever is necessary to express the local character set completely... </straight face>
Donal Fellows
c1x gives us uint8_t (or something like that) for implementations that have an 8-bit type (and the other specific bit widths). I do love the idea of a 24-bit short long for RGB values.
paxdiablo
`echo 'long long long x;' | gcc -c -x c -`
Roger Pate
@Donal: I actually think `short long` would be useful for something such as `int24_t`, it's a type that's often needed in embedded and low level programming - e.g. what C/C++ are good at.
Joe D
@Joe: I'd have thought that would be a `long short`. ;-)
Donal Fellows
Or `short short long long`?
Joe D
Humour aside, neither a short long nor a long short would have a _specific_ bit width, that's what the new intN\_t's are for. They'd just be between short and long bit widths. Then all you have to decide is whether a short long should be longer than a long short.
paxdiablo
If you want a specific width, you need a numeric type that's larger and to then use the `:17` suffix (in this case, for a 17-bit type). I think; I'm a bit shaky on bitfield stuff since I don't bother to use it in my code. :-) (and @Joe: +1 for the greatest C type yet!)
Donal Fellows
A: 

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.

Evgeny
+1  A: 

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).

Dean Harding
Sometimes standards lag what's out there, rubber stamping common practice (and hopefully not blessing too many nasty things in the process).
Donal Fellows
A: 

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.

Will
A: 

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".

Danvil