Is there any benefit in typedef-ing the same identifier as shown below:
typedef struct Struct_name
{
//something....
} Struct_name;
I have come across this style mostly with struct
C++ already allows you to refer to struct Struct_name
as Struct_name
. But it has a special rule that permits this alias to declare the same identifier to Struct_name
via typedef.
The reason is C compatibility. In C, struct Struct_name
can only be referred to as Struct_name
when that typedef
is present. So what you see allows one to put this structure in a header that is included by both C and C++ code. Thus letting both code bases refer to the type as both struct Struct_name
and Struct_name
.