"Martin Vorbrodt" <mv*******@poczta.onet.pl> wrote in message
news:dk**********@news.onet.pl...
: why would you bother writing:
:
: typedef struct S {
: } S_t;
:
: instead of just:
:
: struct S {
: };
:
: and the just use S, or struct S (in plain C) ?
:
: what is the advantage of declaring struct S and then a typedef for it
S_t
: ???
What I would typically see is more something like:
typedef struct S_t { /*...*/ } S;
This style trick is useful in C code, to allow one to use 'S'
alone as a type identifier (instead of being required to always
prepend the keyword 'struct' to refer to the struct type in C).
The 'S_t' struct identifier is optional above. It can be useful
when one wants to forward-declare 'S':
typedef struct S_t S; // forward declaration of S, would not
// be possible without 'S_t' in the decl.
This typedef trick is totally pointless in C++, except when
a more transparent backwards-compatibility with C is desired.
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <>
http://www.brainbench.com