Let's say I have a stacked 2 layer app (High Layer (HL) and Low Layer (LL)) that is implemented in C.
HL defines a few #defines.
HL calls a LL function with a parameter that takes values of the #define.
LL wants to check these values and proceed accordingly.
Now my question is what is the best way to share these #defines.
Option 1: Duplicate them in the LL.
Cons: Introduces duplicity.
Option 2: Include the header of the HL layer.
Cons: LL layer shouldn't have to know about the HL
Option 3: Break the shared #defines of HL and LL into a new header file shared_defs.h which both of them include.
Cons: Not sure, does this also break encapsulation? I feel like header will be a bit standalone.
Which is the best option?
HL.h
#define INIT_STATE (0)
#define RUN_STATE (1)
void HL_Init(void);
HL.c
#include "HL.h"
#include "LL.h"
void HL_Init(void) {
LL_Init(INIT_STATE);
LL_Init(RUN_STATE;
}
LL.h
void LL_Init(int state);
LL.c
void LL_Init(int state) {
if (state == INIT_STATE) {
do sth
} else {
do sth else
}
}