
Musings on Structure Declarations
Introduction This article is sort-of a follow-up to my Musings on C & C++ Declarations and Why C Requires the “struct” Keyword for Structures articles specifically focusing on structure ( struct ) declarations. As a preview, all of the following are valid uses of struct (independently, but not necessarily consecutively in the same program): struct point ; // 1 struct point { int x , y ; }; // 2a struct point { int x , y ; } p ; // 2b struct { int x , y ; } p ; // 3 typedef struct { int x , y ; } point ; // 4 typedef struct point { int x , int y ; } point ; // 5a typedef struct point_s { int x , int y ; } point ; // 5b typedef struct point { int x , int y ; } point_t ; // 5c 1. Forward Structure Declaration A declaration like: struct point ; // Forward declaration. is a forward declaration that effectively tells the compiler “ point is a structure” but without any other details. What use is that? It allows you to: Create an opaque type . Break bidirectional type dependencies. An opaque
Continue reading on Dev.to
Opens in a new tab



