Reputation: 115
Ok, so how I understand #include
works is by looking up what you are including and complies that and replaces it where the include is. however, when I assume this, my program doesn't compile and it gives __ is undefined all over the place.
for example when in my main.c will have something like
#include "tim.h"
#include "tim_cfg.h"
#include "tim_api.h"
tim.h contains some typesdef
s like
typedef enum
{
RATE_DIV1 = 0X0,
RATE_DIV2 = 0X1,
RATE_DIV3 = 0X2,
RATE_DIV4 = 0X3,
RATE_DIV5 = 0X4,
RATE_DIV6 = 0X5,
RATE_DIV7 = 0X6,
RATE_DIV8 = 0X7,
RATE_DIV9 = 0X8
} BaseRate_T;
typedef unsigned char byte;
tim_cfg.h contains register locations and basic struct
s
typedef struct
{
byte TimerSize;
byte InterruptLevel;
} TIMInfo_T;
and tim_api.h contains the function prototypes of the tim functions
So, the problem is why do I get errors
identifier "byte" is undefined
When it the first thing I include?
Upvotes: 0
Views: 80
Reputation: 881093
You should follow the rule that every header file should include what it needs to work.
With the setup you have, if someone includes tim_cfg.h
on its own, the byte
type is not defined.
A better solution would be:
tim_cfg.h:
#include "tim.h"
typedef struct
{
byte TimerSize;
byte InterruptLevel;
} TIMInfo_T;
That way, everything that is needed for tim.cfg.h
is there when you include it.
Upvotes: 1