Posted by DaRKFoRCe on 2000-02-07
Hi,
>Date: Sat, 5 Feb 2000 21:26:01 +1000
>From: "Benjamin Johnston" <s355171@xxxxxxx.xx.xxx.xx>
>Subject: typedef struct vs struct
>Snipped...
>typedef struct tagMSG {
> ....
> ....
>} MSG;
>and the other one is:
>struct MSG {
> ...
> ...
>};
Both are basically do the same thing, declaring a structure, but with
one difference, the first one is typedefed. Typedef means telling the
compiler that you want to call some datatype with a different name,
i.e.
typedef char byte;
Now you can call a datatype of char with byte, i.e.
char ch;
byte one;
Both variables have a same type, that is char.
Returning to your question, with the first declaration (the typedefed
one), you can now declare every structure that is of type tagMSG with
only MSG, i.e.
MSG myMessage;
MSG yourMessage;
In contrary, with the second declaration, you must declare all
structures that is of that type with struct keyword, i.e.
struct MSG myMessage;
struct MSG yourMessage;
IMHO, typedefs are for convinience only.
Tip:
if you declare the above structure like this
typedef struct tagMSG{
...
...
} MSG, *LPMSG;
you can declare MSG for all structures of the above type, and LPMSG
for pointer to structure of that type, i.e.
MSG myMessage;
LPMSG theMessage; // (a pointer to structure, the same as if you're
// declaring it with 'MSG *theMessage' or 'struct
// *tagMSG theMessage')
Hope it helps.
DaRKFoRCe
darkforce@xxxxxxxxxxx.xxx
To signoff send a mail to listserver@xxxx.xx.xx with
"signoff tcg" in the body of your message.
Previous post | Next post | Timeline | Home