Consider the following valid code:
typedef enum { STATUS1 = 0, STATUS2 = 1 } status ; // struct tag // | // V struct status { status status ; // ^ ^ // | |_______ // | | // type_name member_name } ; typedef struct status status_t ; // ^ // | // Type alias int main() { // The following is valid status_t status_structure ; status_structure.status = STATUS1 ; // So is this struct status status ; status.status = STATUS1 ; return 0; }
The name of type status is different from the name of the status participant and the struct status tag. Somewhere in the code above, or maybe not included, but necessary, this is a separate definition of the structure, also called status .
In C, a native struct tag is not a type identifier, so there is no ambiguity. struct status not the same type as an alias of the status enumeration type. This is not necessarily a good idea, but it is not invalid. Of course, this would be a mistake if C ++ compilation was used, because then for struct status , status would be a type name, therefore, I would encounter the status enumeration alias.
source share