[Page 1061 (continued)]|
Keyword typedef provides a mechanism for creating synonyms (or aliases) for previously defined data types. Names for structure types are often defined with typedef to create shorter, simpler or more readable type names. For example, the statement
defines the new type name CardPtr as a synonym for type Card *.
Good Programming Practice 22.1
Capitalize typedef names to emphasize that these names are synonyms for other type names.
Creating a new name with typedef does not create a new type; typedef simply creates a new type name that can then be used in the program as an alias for an existing type name.
Portability Tip 22.2
Synonyms for built-in data types can be created with typedef to make programs more portable. For example, a program can use typedef to create alias Integer for four-byte integers. Integer can then be aliased to int on systems with four-byte integers and can be aliased to long int on systems with two-byte integers where long int values occupy four bytes. Then, the programmer simply declares all four-byte integer variables to be of type Integer.