c - What is the advantage of specifying two types when creating a typedef'd struct? -
example 1:
struct t{ int a; };
creates type struct t
example 2:
typedef struct { int a; } t;
creates type t
example 3:
typedef struct t{ int a; } t;
creates both types struct t , t
i tend see example 3 lot, , i'm not sure why choose on example 1 or 2.
- are there advantages gain doing way?
- are there reasons people compatibility?
- is advantageous kind of scoping reason?
i avoid doing example 3 way, because less maintenance on type, , restricts multiple ways of declaring same thing. however, reconsider it, if there benefits "double naming" technique.
i tend see example 3 lot, , i'm not sure why choose on example 1 or 2.
- are there advantages gain doing way?
i hold truth self-evident, namely cumbersome code cumbersome. prefer write
t object;
instead of
struct t object;
however, hard-core c coder might think hey, t
struct, better call that , also, mitigates chance confusion you'd when doing
struct {int a; } t; typedef int t;
- are there reasons people compatibility?
yes. way, structs in c can used used in c++.
- is advantageous kind of scoping reason?
no, not i'd aware of.