liveBook · Manning

Type alias

As explained in Modern C

A type alias is an alternative name for an existing C type that does not create a distinct type.

One array type, several names

typedef double matrix[16][64]; matrix B; double C[16][64]; B and C have the same type. A typedef gives matrix as another way to write double[16][64]; it does not create a distinct type. section 6.4

A type alias is an alternative name for an existing C type. The typedef mechanism can name structures, arrays, and other types, but the alias and the original type remain identical. section 6.4

TAKEAWAY

  • A typedef creates an alias, never a new type. section 6.4
  • A structure can be forward-declared within a typedef by repeating the same identifier as its tag. section 6.4
  • Names ending in _t are reserved because the C standard uses that convention for typedef names; do not introduce such names yourself. section 6.4 section 2.1
typedef double vector[64];
typedef vector vecvec[16];
vecvec A;
typedef double matrix[16][64];
matrix B;
double C[16][64];


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":14}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":14}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":7}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":7}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":7}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":14}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":14}],[{\"line\":0,\"ch\":8},{\"line\":0,\"ch\":14}],[{\"line\":3,\"ch\":8},{\"line\":3,\"ch\":14}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":6}]]"}
!@%STYLE%@!

Compare aliases built in stages with equivalent declarations written directly as multidimensional arrays. section 6.4

How Modern C covers it

How deep it goes
Explains alias identity, structure forward declarations, array syntax, and _t reservation rules.
Examples
Uses multidimensional double arrays, staged array aliases, structure declarations, and size_t as examples.
What it assumes
Assumes basic C identifiers and declarations while establishing aliases through concrete structure and array examples.
What you can do after
Apply it via typedef to name existing structures, arrays, and other C types without changing their identities.
How it connects
Connects typedef with structures, forward declarations, arrays, identifiers, and standard typedefs such as size_t.

Also explained in

Compare how 6 books explain type alias →

Related concepts

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