This may have been asked before and may also be trivial, but I'm curious between the differences of:
and:Code:struct ANYTYPE { // members };
Would be muchly appreciated to hear some thoughts.Code:typedef struct TYPENAME { // members } ANYTYPE;
This may have been asked before and may also be trivial, but I'm curious between the differences of:
and:Code:struct ANYTYPE { // members };
Would be muchly appreciated to hear some thoughts.Code:typedef struct TYPENAME { // members } ANYTYPE;
When you name a structure with a tag like so,
you're declaring a structure tag that can be used together with the struct keyword to declare an instance of that structure.Code:struct tag { };
When you use a typedef like this,Code:struct tag instance;
you're declaring a typedef by the name of tag which happens to map to a structure, and which you can use like this, without the "struct" keyword.Code:typedef struct { } tag;
Basically, using typedef lets you leave off the struct keyword everywhere else.Code:tag instance;
(BTW, this is a C phenomenon. In C++, you can declare an instance of a struct or a class with just the tag name, with no typedef required.)
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.