Is it good/correct way to do like this for a robust C program
//File1 => Module1.h
static int Fun(int);
struct{
int (*pFn)(int)
}Interface;
//File2 => Module1.c
static int Fun(int){
//do something
}
Interface* Init(void)
{
Interface *pInterface = malloc(sizeof(Interface));
pInterface->pFn = Fun;
return pInterface;
}
//File 3 => Module2.c
#include"Module1.h"
main()
{
Interface *pInterface1 = Init();
pInterface1->pFn(5);
}
My intention is to make each module expose an interface...
Questions:
- Is it good to write a C code like above to expose an interface... ??
- What better ways are available for exposing interface??
- Are there any references for design principles for C programming (not C++) ??