What is int?

The must misused datatype in C is int. It's misused can be catastrophic. So the question is, what is int and what is it not. And as a bonus, this article will cover all important intrinsic types.

Most C programmers know that char is the smallest addressable unit of memory. This is not necessarily 8 bits, although that is usally the case on contemporary computers, but there are still modern CPUs where this is 16. In C, char does not specify whether it is signed or unsigned, although I don't know why, my guess is that it is because int is signed by default, but some platforms have both +0 and -0, putting the range of a signed 8-bit integer at [−127, 127], which is only 28−1 distinct values, and not 28, so on those platforms, it makes more sense to have this type unsigned, as it is usually used for text characters and not numerical values.

This brings us to int which although it is not necessarily to smallest integer type, it is the smallest integer type that is at least 16 bits (sidenote, implicit int is used as int_least16_t, except without its two's complement requirement) wide and that the CPU can do arithmetics (or bitwise operations) on. If you ever done arithmetics over (or bitwise operations on) smaller integer types, and put your warnings on, you might have found that the compiler adds implicits casts to int, and that you have to cast down to the origial type to get rid of the warnings.

int is often mistakenly used for array indices and even sizes. That is where long comes in. long is smallest integer type that (albeit as a guideline that Windows breaks for backwards-compatibility) covers all memory addresses. You should however not use long, instead POSIX provides semantic aliases: size_t for sizes, indicies and offsets, and its signed version ssize_t, intptr_t and uintptr_t for memory addresses, and ptrdiff_t for differences between memory addresses.

Despite the name float is anything but the prime float-point type. On most x86 chips, this would actually be that 80-bit type; unfortunately there is not C type for this type as long double is only guaranteed to be at least as precise as double and some compilers define it as a non-intrinsic 128-bit type. As long as you are using the scalar floating-point instruction you will, on an x86 chip, find that double is faster than float, this is because of casting done by the CPU. (As long as the compiler defines long double as at least 80-bit, it can hold any unsigned 64-bit integer without loss of precision.)