C Use of the typedef struct tag

C Language Simple Uses of Typedef


For giving short names to a data type

Instead of:

one can use

This reduces the amount of typing needed if the type is used many times in the program.

Improving portability

The attributes of data types vary across different architectures. For example, an may be a 2-byte type in one implementation and an 4-byte type in another. Suppose a program needs to use a 4-byte type to run correctly.

In one implementation, let the size of be 2 bytes and that of be 4 bytes. In another, let the size of be 4 bytes and that of be 8 bytes. If the program is written using the second implementation,

For the program to run in the first implementation, all the declarations will have to be changed to.

To avoid this, one can use

Then, only the statement would need to be changed each time, instead of examining the whole program.


The header and the related header define standard type names (using) for integers of various sizes, and these names are often the best choice in modern code that needs fixed size integers. For example, is an unsigned 8-bit integer type; is a signed 64-bit integer type. The type is an unsigned integer type big enough to hold any pointer to object. These types are theoretically optional - but it is rare for them not to be available. There are variants like (the smallest unsigned integer type with at least 16 bits) and (the fastest signed integer type with at least 32 bits). Also, and are the largest integer types supported by the implementation. These types are mandatory.

To specify a usage or to improve readability

If a set of data has a particular purpose, one can use to give it a meaningful name. Moreover, if the property of the data changes such that the base type must change, only the statement would have to be changed, instead of examining the whole program.