On Mon, 26 Jun 2006 15:01:00 -0700, Tom Plunket <>
wrote:
<snip>
> It's been years since I "learned" C, but at the time the sage wisdom
> who was providing me with guidance said I should /always/ typedef
> structures, because a structure definition all by itself would yield
> an unnamed instance of that structure right at that location. E.g.
>
> struct something
> {
> int member;
> };
>
Does not, and never did, as already said.
Are you sure you, or your guide, didn't misunderstand or misremember
the issue of including or omitting a struct _tag_?
struct { elements } zorg;
creates an 'anonymous' struct type, which you cannot refer to later --
i.e. you cannot create another variable, or a pointer to one, or a
function argument, etc., which the compiler will recognize as the same
type. (Unlike some other non-C languages, which do use so called
'structural' or 'deep' type compatibility.)
struct good { elements } lelu;
creates a variable _and_ a tag (type) which you can use later.
struct good { elements };
creates _only_ the tag (type). Which you can use later,
and that is the only way to use it, so if you don't, it's useless
<OT> In C++, the tag name(s) in the latter form are available as
typenames by themselves, in addition to 'struct good' as in C (which
is still permitted). People often say loosely that C++ automatically
does typedef for you, but this isn't strictly right; even in C++ you
can still declare both an ordinary-identifier foo and a tag foo in the
same scope, but it is very bad style, even worse than it is in C.
- David.Thompson1 at worldnet.att.net