The pointers function declarations in the following snippets of code allows me to vary the names of each function inside the struct, correct? This is merely hypothetical, so the names are of no consequence yet.
Header File
typedef struct
{
bool (*enabled)(uint32_void);
void (*start)(uint32_t);
void (*stop)(uint32_t);
bool (*expired)(void);
} battle_star_gallactica;
C File
static bool Battle_v0_enabled (void) { ... }
static void Battle_v0_start (uint32_t) { ... }
static void Battle_v0_stop (uint32_t) { ... }
static bool Battle_v0_stop (void) { ... }
const battle_star_gallactica battle_v0 =
{
enabled,
start,
stop,
expired
};
...
One Example Use
battle_v0.start(1000);
The C file snippet would be repeated for other versions (e.g. v1 or v2 instead of v0).
How does this work?
EDIT
Corrected code:
Header File
typedef struct
{
bool (*enabled)(uint32_void);
void (*start)(uint32_t);
void (*stop)(uint32_t);
bool (*expired)(void);
} battle_star_gallactica;
extern const battle_star_gallactica battle_v0;
extern const battle_star_gallactica battle_v1;
...
C File
static bool Battle_v0_enabled (void) { ... }
static void Battle_v0_start (uint32_t val) { ... }
static void Battle_v0_stop (uint32_t val) { ... }
static bool Battle_v0_expired (void) { ... }
const battle_star_gallactica battle_v0 =
{
Battle_v0_enabled,
Battle_v0_start,
Battle_v0_stop,
Battle_v0_expired
};
...
One Example Use
battle_v0.start(1000);