typedef int Int is a terrible idea ... people will wonder if they look at C ++, it’s hard to type, visually distract, and the only vaguely imaginary rationalization for it is wrong, but let's lay it out explicitly so that we can get it down:
if one day you say that a 32-bit application is ported to 64-bit, and there is a lot of stupid code that works only for 32-bit ints, then at least the typedef can be changed to save Int to 32 bits.
Criticism: if the system sucks in code that is so poorly written (that is, it does not explicitly use the 32-bit type from cstdint), it for the most part has other parts of the code where now it will need to use 64-bit, which gets stuck in 32 bit mode using typedef. Code that interacts with library / system APIs using ints is likely to get Ints, which will lead to truncated descriptors that work until they fall outside the 32-bit range, etc. The code will need to be fully tested before being reliable in any case. If this excuse floating around people can only prevent them from using explicitly sized types, where they are really useful ("what are you doing this for?" "Portability?" "But Int for portability, just use this").
However, coding rules can be designed to encourage typedef for things that are logically distinct types, such as temperatures, prices, speeds, distances, etc. In this case, typedefs can be vaguely useful, because they allow an easy way to recompile the program to say that updating is accurate from float to double , switching from a real type to an integral type, or replacing a user-defined type with special behavior. This is also convenient for containers, so changing the container has less work and less impact on the client, although such changes are usually a little painful: the container APIs are designed to be a little incompatible, so important details need to be reviewed and not compiled but not working or silently working much worse than before.
It is important to remember that typedef is only an “alias” for the actual base type and does not actually create a new separate type, so people can pass any value of the same type without receiving any compiler warning about type mismatches. This can be processed using a template, for example:
template <typename T, int N> struct Distinct { Distinct(const T& t) : t_(t) { } operator T&() { return t_; } operator const T&() const { return t_; } T t_; }; typedef Distinct<float, 42> Speed;
But it’s a pain to make unique N values ... you can have a central enum list of individual values or use __LINE__ if you are dealing with one translation unit and several multiple typedefs on a line or take const char* from __FILE__ , but not really an elegant solution that I know of.
(One classic article from 10 or 15 years ago demonstrated how you can create patterns for types that knew about several orthogonal units, while preserving current “power” counters and setting the type as multiplications, divisions, etc. For example, you you can declare something like Meters m; Time t; Acceleration a = m / t / t; and check if all units were reasonable at compile time.)
Is that a good idea? Most people clearly find this unnecessary, since almost no one ever does it. However, this can be useful, and I used it several times when it was easy and / or especially dangerous if the values were accidentally incorrectly assigned.