What the difference between "typedef struct" and "typedef struct tag_Struct"? 
Author Message
 What the difference between "typedef struct" and "typedef struct tag_Struct"?

HI:
There are two style to define a new data type,one is
 typedef struct
{
int a;
int b;

Quote:
}TMail;

the other is

 typedef struct tag_Struct
{
int a;
int b;

Quote:
}TMail;

What the diffenerce?
Thank you!

Sincerely,
Bryan



Fri, 11 Feb 2005 16:26:45 GMT  
 What the difference between "typedef struct" and "typedef struct tag_Struct"?

Quote:
> HI:
> There are two style to define a new data type,one is
>  typedef struct
> {
> int a;
> int b;
> }TMail;
> the other is
>  typedef struct tag_Struct
> {
> int a;
> int b;
> }TMail;
> What the diffenerce?
> Thank you!

The only difference is that in the first code sample, you're creating
the name "TMail" as an alias to an unnamed structure, while in the
second sample, you're creating the name "TMail" as an alias to a
structure named "struct tag_Struct".
Despite its name, typedef does not create new types. It creates new
names for already existing types. In your first code sample, the
already existing type doesn't have a name yet, but in your second
sample, its name is "struct tag_Struct".
What does this mean in practice? In your first example you can only
refer to your structure type as "TMail". In your second one, you
can refer to it either as "TMail" or "struct tag_Struct".

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"Shh! The maestro is decomposing!"
   - Gary Larson



Fri, 11 Feb 2005 16:30:37 GMT  
 What the difference between "typedef struct" and "typedef struct tag_Struct"?


Quote:
> The only difference is that in the first code sample, you're creating
> the name "TMail" as an alias to an unnamed structure, while in the
> second sample, you're creating the name "TMail" as an alias to a
> structure named "struct tag_Struct".

Generally you don't need the tag, unless the structure contains a pointer to
another structure of the same type

eg typedef struct Node_tag;
{
  struct Node_tag *parent;
  struct Node_tag *sib;
  struct Node_tag *child;
  int data;

Quote:
} Node;



Sat, 12 Feb 2005 04:39:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. interpreting "typedef struct x* y"

2. "typedef specifies different struct"

3. Typedef structs within typedef structs...

4. Typedef structs within typedef structs...

5. A "How to typedef..." Question

6. What's The Difference Between "typedef void *" and "void *"??

7. struct vs. typedef struct

8. "struct" initialization question

9. "dynamic" struct

10. "_flag" field in struct FILE

11. the "struct hack" - FAQ 2.6

12. What is a "spooty struct"?

 

 
Powered by phpBB® Forum Software