liveBook · Manning

Hierarchy

As explained in Modern C

A nested structure is a structure declaration or member arrangement in which one structure type is declared within or contains another structure type.

A person can contain a birth date, while that birth date contains both a calendar date and a time precision. In C, this arrangement uses a structure member whose type is another structure type. section 6.3

struct stardate {
  struct tm date;
  struct timespec precision;
};
struct person {
  char name[256];
  struct stardate bdate;
};


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":8}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":8}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":6}],[{\"line\":6,\"ch\":2},{\"line\":6,\"ch\":8}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":8}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":8}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":6}],[{\"line\":6,\"ch\":2},{\"line\":6,\"ch\":8}],[{\"line\":1,\"ch\":9},{\"line\":1,\"ch\":11}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":8}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":8}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":6}],[{\"line\":6,\"ch\":2},{\"line\":6,\"ch\":8}],[{\"line\":2,\"ch\":9},{\"line\":2,\"ch\":17}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":8}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":8}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":6}],[{\"line\":6,\"ch\":2},{\"line\":6,\"ch\":8}],[{\"line\":5,\"ch\":2},{\"line\":5,\"ch\":6}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":8}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":8}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":6}],[{\"line\":6,\"ch\":2},{\"line\":6,\"ch\":8}]]"}
!@%STYLE%@!

This listing separates the inner stardate declaration from the person declaration, making the nesting visible through the bdate member. section 6.3

C permits any member type other than a variable-length array, so structures may contain other structures. A nested declaration may also be written inside the outer structure declaration, but that placement does not create a new struct scope. section 6.3

TAKEAWAY 6.28: All struct declarations in a nested declaration have the same visibility scope. At file level they remain visible throughout the file; inside a function, visibility is limited to the enclosing block. section 6.3

How Modern C covers it

How deep it goes
Explains permitted member types, nested declarations, and scope consequences, but stops short of memory-layout details.
Examples
Uses person, stardate, timespec, tm, and birth-date records to demonstrate nested structure declarations.
What it assumes
Assumes familiarity with C structures and members while clarifying nested declaration scope explicitly.
What you can do after
Builds nested C structures and predicts declaration visibility at file and block scope.
How it connects
Connects structures with structure members, variable-length arrays, scope, and visibility.

Also explained in

Compare how 7 books explain hierarchy →

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.