liveBook · Manning

Typedef

As explained in Modern C, Third Edition

A typedef is a C declaration that introduces an alias for an existing type.

A typedef introduces an alias for an existing C type; it does not create a distinct type. For example, a structure can receive a convenient name before or alongside its declaration: section 6.0 section 6.4

Aliasing a structure tag

typedef struct birdStruct birdStructure; typedef struct birdStruct birdStruct; struct birdStruct { ... }; The identifiers struct birdStruct, birdStruct, and birdStructure can then be used interchangeably for the same structure type. section 6.4

Use typedef according to these rules:

  • Alias existing types without treating the aliases as new types. section 6.4
  • Forward-declare a structure within a typedef by reusing its tag identifier. section 6.4
  • Use implementation-provided names such as size_t for sizes, cardinalities, and ordinal numbers. section 5.2
  • Avoid introducing identifiers ending in _t because those names are reserved. section 6.4
typedef double vector[64];
typedef vector vecvec[16];
vecvec A;
typedef double matrix[16][64];
matrix B;
double C[16][64];

Shows typedef aliases for multidimensional arrays, including equivalent declarations using vector, vecvec, matrix, and a direct array type. section 6.4

How Modern C, Third Edition covers it

How deep it goes
Explains aliasing, structure forward declarations, arrays, reserved names, and semantic typedefs, without descending into compiler implementation.
Examples
Demonstrates structure aliases, array aliases, multidimensional arrays, and implementation-provided names including size_t and ptrdiff_t.
What it assumes
Assumes familiarity with C declarations and basic types, then develops derived types through structures, arrays, and aliases.
What you can do after
Apply typedef to name existing structure, array, and implementation-provided types while preserving type identity and naming constraints.
How it connects
Connects typedef with structures, arrays, macros, forward declarations, basic types, and semantic types such as size_t.

Also explained in

Compare how 2 books explain typedef →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.