Unless you have dire performance needs use snprintf to manipulate string, it is the best all around function.
On topic, most times I have seen heritage system its was like this:
#include <stdio.h>
#define DEFAULT_BUFFER_SIZE 64
struct Employee_t {
char name[DEFAULT_BUFFER_SIZE];
float wage;
};
typedef struct Employee_t Employee;
struct Manager_t {
Employee super;
char title[DEFAULT_BUFFER_SIZE];
};
typedef struct Manager_t Manager;
struct Intern_t {
Employee super;
char college[DEFAULT_BUFFER_SIZE];
};
typedef struct Intern_t Intern;
...
...
Or even better:
typedef struct {
char name[DEFAULT_BUFFER_SIZE];
float wage;
} Employee_t;
typedef struct {
Employee_t super;
char title[DEFAULT_BUFFER_SIZE];
} Manager_t;
typedef struct {
Employee_t super;
char college[DEFAULT_BUFFER_SIZE];
} Intern_t;
No need to separate out the typedef and struct definitions in C, and, personally, if you're going to typedef something, it should have the '_t' modifier, not the struct definition that isn't even used.
Can you point me any advantage other than coding style? I like to split the declarations from the typedef, I find that it has better reabability when the structs are bigger.
What's the point of defining the name of the structure if you're not going to use it? If you have a pointer in the struct point to itself (Link list), then it makes sense. If you're not going to typedef it, then it makes a little sense. But, if you give the struct a name and define a typedef for it, I don't see the point. That's just me.
Also, you've named the structure with *_t...for what purpose? I would've thought the _t defines a type. If you're going to name the struct, using _s would've made more sense in this case.
Personally, I precede my typedef's with a "T", but it just coding style (and, POSIX doesn't have reign over how people choose to define their types).