Is "long" still useful in C?
c
Solution
There's a subtle difference between `still useful` and `something you should habitually use`. The `long` type still thrives, as Chris Lutz noted behind many system and platform specific types (though, usually as unsigned).
When you know the data you will be working with is always going to fit in that type (agreeably, better if you also know the signedness), there is no particular reason not to use it, especially if you have limited space in a structure to work with.
However, in most cases, for the sake of future maintainers, its much better to use intxx_t or uintxx_t wherever possible. For instance, you don't know that a UNIX epoch date will always fit inside an unsigned long on 32 bit platforms (hence, time_t), unless you have it on good authority that the world will end before it rolls over :)
Problem
- It's not the largest integer type anymore now that there's "long long". - It's not a fixed-width type: It's 32 bits on some platforms and 64 on others. - It's not necessarily the same size as a pointer (for example, on 64-bit Windows) So, does "long" have any meaning anymore? Is there ever a reason to declare a long instead of a ptrdiff_t or int64_t?