S
Serve La
When I write a medium to large sized C application I tend to create
structures first, then makeStruct and freeStruct functions that dynamically
allocate/free the struct and then I create a bunch of functions that operate
on the struct. Example:
typedef struct ccHashTab
{
.....
} ccHashTab;
ccHashTab * ccMakeHash(unsigned int size, hash h, comp c);
void ccFreeHashTab(ccHashTab *table);
void *ccHashFindSym(ccHashTab *table, void *symbol);
......
This is a bit the object-oriented way, because I never touch the struct
members directly, only inside the hash functions.
Now I'm wondering if this is a style that other C programmers use in their
work or if they're using something different. I just want to know some
opinions, maybe I'll get some new insights.
structures first, then makeStruct and freeStruct functions that dynamically
allocate/free the struct and then I create a bunch of functions that operate
on the struct. Example:
typedef struct ccHashTab
{
.....
} ccHashTab;
ccHashTab * ccMakeHash(unsigned int size, hash h, comp c);
void ccFreeHashTab(ccHashTab *table);
void *ccHashFindSym(ccHashTab *table, void *symbol);
......
This is a bit the object-oriented way, because I never touch the struct
members directly, only inside the hash functions.
Now I'm wondering if this is a style that other C programmers use in their
work or if they're using something different. I just want to know some
opinions, maybe I'll get some new insights.