Programming languages (e.g. c, c++, and java) usually have several types for integer arithmetic:
signed
and unsigned
types
The default integral type (int
) gets a "first among equals" preferential treatment in pretty much all languages. So we can use that as a default, if no reasons to prefer another type exist.
Such reasons might be:
<<
and >>
).int32_t
) -- if your program is meant to be portable and expected to be compiled with different compilers, this becomes more important.Update (expanding on guaranteed size types)
My personal opinion is that types with no guaranteed fixed size are more trouble than worth today. I won't go into the historical reasons that gave birth to them (briefly: source code portability), but the reality is that in 2011 very few people, if any, stand to benefit from them.
On the other hand, there are lots of things that can go wrong when using such types:
For these reasons (and there are probably others too), using such types is in theory a major pain. Additionally, unless extreme portability is a requirement, you don't stand to benefit at all to compensate. And indeed, the whole purpose of typedefs like int32_t
is to eliminate usage of loosely sized types entirely.
As a practical matter, if you know that your program is not going to be ported to another compiler or architecture, you can ignore the fact that the types have no fixed size and treat them as if they are the known size your compiler uses for them.