If I structure my C program like this will it keep the compile times down as the project grows?
#include <stdio.h>
#include "lib/manager/manager.h"
#include "lib/loop/loop.h"
#include "lib/utility/utility.h"
int main()
{
FN fn;
dev_loop_init(&fn);
dev_utility_init(&fn);
fn.util.log("test");
return 0;
}
A manager.h header file which I will include in every "module".
#ifndef DEV_MANAGER
#define DEV_MANAGER
typedef struct {
void (*start) (void);
void (*stop) (void);
} Loop;
typedef struct {
void (*log) (char* message);
} Utility;
typedef struct {
Loop loop;
Utility util;
} FN;
#endif
An example module, loop.h.
#include "../manager/manager.h"
#ifndef DEV_LOOP
#define DEV_LOOP
void dev_loop_init(FN *fn);
#endif
And the loop.c functions
#include "loop.h"
static void dev_loop_start(){}
static void dev_loop_stop(){}
void dev_loop_init(FN *fn)
{
fn->loop.start = &dev_loop_start;
fn->loop.stop = &dev_loop_stop;
}
You need to sign in to view this answers
Leave feedback about this