1

I saw some code in C header like this:

//a.h

typedef struct name name;

//a.c

struct name {
   int number;
   int age;
};

what is the reason why typedef struct in header file? and kind of implement it in source file?

Why not just define the struct in header file? what is the propose of doing this?

ratzip
  • 1,571
  • 7
  • 28
  • 53

1 Answers1

0

typedef keyword is used to create synonyms, so that later in your code you can use just your typedefed keyword instead of struct or any primitive type you replaced.

Michał Szydłowski
  • 3,261
  • 5
  • 33
  • 55
  • While you're very right, I don't think this is the anser OP is looking for. What you told is already known to him/her. Google about _opaque type_ :-) – Sourav Ghosh Apr 08 '15 at 14:12