typedef meaning

hi, I saw in some code examples with some conventions when defining typedef structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// example A
typedef struct _NAME_A
{
    int a;
    int b;
} NAME_A

// example B
typedef struct _NAME_B
{
    int a;
    int b;
}

// example C
typedef struct
{
    int a;
    int b;
}NAME_C


is there any difference between definition or using like?

1
2
3
4
_NAME_A var_a1;
NAME_A var a2;
NAME_B var_b;
NAME_C var_c;


Thanks
Last edited on
In example A _NAME_A is called as tag_name and NAME_A is called as type_name. As we have used typedef, we can only create variable using tag_name so
NAME_A var_a2 will give an error
else all are correct
Note: After struct whichever name comes first that will be called as tag_name.
So NAME_c var_c is also correct
Last edited on
is there any difference between definition or using like?
1
2
_NAME_A var_a1;
NAME_A var a2;

No, there is no difference.
The pracrice of typedeffing structs to themselves is a C programming idiom, where otherwise you would have to write
1
2
struct _NAME_A var_a1;
NAME_A var_a2;

closed account (zb0S216C)
There are some rules to type-defining a structure: http://www.cplusplus.com/forum/beginner/89419/#msg480308

Wazzak
Topic archived. No new replies allowed.