5.13.5. Additional Issues on Structures


Incomplete structure types

Sometimes you need to use a pointer type, such as Cell*, but you do not need to use type Cell by itself. That can happen when you are describing an abstract data type that uses another type. A module that only uses the abstract data type might only need to know that type Cell exists, and does not need any details about what type Cell looks like.

Write

  struct Cell;
to indicate that structure type Cell exists without providing any information about it. You will be able to use type Cell* with only this information. But in the module that implements the abstract data type, provide a complete definition of type Cell.


Recursive structure type definitions

When a structure type definition is started, its name immediately becomes available. In the definition of type S you can include a field of type S*. For example, type definition

  struct ListCell
  {
    ListCell* next;
    int       item;
  };
indicates that a value of type ListCell has two fields, one of which is a pointer to a ListCell. We will see uses of this when looking at data structures.