Typedef and Structs

K

kasiyil

Hello everyone,

I have a question about using typedef with structure definitions. Here
is the example;

typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};

Thanks for your answers...
 
V

Victor Bazarov

kasiyil said:
I have a question about using typedef with structure definitions.
Here is the example;

typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};

The effect is that in the former case you have two names, 'MyStruct',
a type-id, and 'MyStruct_t', a typedef-id, which is a synonym for it;
and in the latter case you have only one name, 'MyStruct_t' which is
a type-id. The difference is minimal, as you can see.

V
 
B

Bart

kasiyil wrote:
typedef struct MyStruct {
...
..
..
} MyStruct_t;

What is the effect of using typedef in this example? What is the
difference of it between the example below

struct MyStruct_t {
...
..
..
};

In C it is necessary to use a typedef if you want to refer to a struct
type without using the keyword struct. In C++ this is no longer
necessary, but there is lots of legacy code that still does this.

Regards,
Bart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top