
Why C Requires the “struct” Keyword for Structures
Introduction Regardless of whether you’ve been programming in C for many years or have only recently started, you might wonder why structure declarations require that the struct keyword be included. For example: struct point { int x , y ; }; point p1 ; // Error: "struct" required. struct point p2 ; // OK. Obviously, struct is needed to declare a structure, but that’s not what this article is about. This article is about why, once declared, struct is still needed to use the previously declared structure type. If you omit struct , the compiler still knows what you mean , but it pedantically requires that you include the struct keyword anyway. If you’ve programmed in other languages, this requirement seems even more curious because no other language that allows you to declare “structure” (Go), “record” (Pascal), or “class” (C++, Java, Python, and many others) types requires repeating a keyword when you use the type. In other languages, such a type becomes a “first class citizen” that can
Continue reading on Dev.to
Opens in a new tab




