Unnamed Structures and Enumerations in C

The C language allows anonymous struct and enum definitions in type definitions. Using such definitions prevents the compiler from properly applying program-level interprocedural analysis. Make sure to give names to structures and enumerations in type definitions. The following listing shows an example of unnamed structures and enumerations.

Listing: Unnamed structures and enumerations in C
/* In C, the types x_rec and y_enum each represent a structure and an 
enumeration with no name.
   In C++ these same statements define a type x_rec and y_enum, 

   a structure named x_rec and an enumeration named y_enum. 

*/

typedef struct { int a, b, c; } x_rec;

typedef enum { Y_FIRST, Y_SECOND, Y_THIRD } y_enum;

The following listing shows a suggested solution.

Listing: Naming structures and enumerations in C
typedef struct x_rec { int a, b, c; } x_rec;
typedef enum y_enum { Y_FIRST, Y_SECOND, Y_THIRD } y_enum;