|
|
Defining typedef names for incomplete structure and union types is frequently quite useful. If one has a complicated bunch of data structures that contain many pointers to each other, having a list of typedefs to the structures up front (possibly in a central header) can simplify the declarations.
Moreover, for those structures and unions whose contents should not be available to the rest of the program, a header can declare the tag without the content. Other parts of the program can use pointers to the incomplete structure or union without any problems (unless they attempt to use any of its members).typedef struct item_tag Item; typedef union note_tag Note; typedef struct list_tag List; . . . struct item_tag { . . . }; . . . struct list_tag { List next; . . . };
A frequently used incomplete type is an external array of unspecified length. It generally is not necessary to know the extent of an array to make use of its contents:
extern char tzname[]; . . . (void)fputs("Alternate time zone: ", stdout); (void)puts(tzname[1]);