From: http://blog.vckbase.com/smileonce/archive/2005/01/15/2578.aspx
There are some books that explain struct in detail, which are easy to confuse, and there are detailed descriptions in Expert C programming. It is a pity that people prefer to ask questions and read books, so BBS is flooded with problems that have been solved and explained by our predecessors. Ah, the sorrow of the Chinese diligent and easy-to-Ask. Here we will briefly describe struct to save money.
/* Struct. c
* BookProgramDemonstrate various methods of writing struct. Note that all these statements can be compiled
* Author: smileonce
* Date: 2005-01-14
*/
// This method is the most terrible, but it can be passed. The Foo at the end is an instance of the struct.
Struct Foo
{
Int Foo ;
} Foo ;
// With typedef, the meaning is obviously different from above. Note that the label behind struct can be left empty, and the bar at the end is the alias of the anonymous structure.
Typedef struct
{
Int Bar;
} Bar ;
// This method is least usable because it is defined as one-time. struct1 is an example of an anonymous struct.
Struct
{
Int Aaa ;
} Mystruct1 ;
// The most common method is clear and self-evident. my_struct_tag is the struct tag, and my_struct_type is the alias of struct my_struct_tag.
Typedef struct My_struct_tag
{
Int Aaa ;
} My_struct_type ;
// The writing methods of the following two definitions are acceptable. Of course, the method of using typedef definition is more concise.
My_struct_type mystruct2 ; // Define the variable through the structure alias defined by typedef
Struct My_struct_tag mystruct3 ; // Define variables using structure labels
Int Main ( Int Argc , Char * Argv [])
{
Return 0 ;
}