typedef

[3][4] In the C standard library and in POSIX specifications, the identifier for the typedef definition is often suffixed with _t, such as in size_t and time_t.

This creates the type length as a synonym of the type int:A typedef declaration may be used as documentation by indicating the meaning of a variable within the programming context, e.g., it may include the expression of a unit of measurement or counts.

The definition in congratulate() of your_score indicates to the programmer that current_speed (or any other variable not declared as a points) should not be passed as an argument.

The correspondence between this C++ feature and typedef is very strong, extending to the fact that it is possible to shadow the simple type name in a nested scope by declaring it as the identifier of another kind of entity.

For example: Above, intptr cliff, allen; means defining 2 variables with int* type for both.

Again, because typedef defines a type, not an expansion, declarations that use the const qualifier can yield unexpected or unintuitive results.

Consider this: Using typedef, the above code can be rewritten like this: In C, one can declare multiple variables of the same type in a single statement, even mixing structure with pointer or non-pointers.

The preceding code may be rewritten with typedef specifications: Here, MathFunc is the new alias for the type.

For instance, to have stringpair represent std::pair for every type T one cannot use: However, if one is willing to accept stringpair::type in lieu of stringpair, then it is possible to achieve the desired result via a typedef within an otherwise unused templated class or struct: In C++11, templated typedefs are added with the following syntax, which requires the using keyword rather than the typedef keyword.

[1] First, it provides a means to make a program more portable or easier to maintain.

Second, a typedef can make a complex definition or declaration easier to understand.

Most arguments center on the idea that typedefs simply hide the actual data type of a variable.

For example, Greg Kroah-Hartman, a Linux kernel hacker and documenter, discourages their use for anything except function prototype declarations.

He argues that this practice not only unnecessarily obfuscates code, it can also cause programmers to accidentally misuse large structures thinking them to be simple types.