I have a register file (.h) with optional settings in an array.
If the header file is enclosed, the array should be written.
If the header file is not enclosed, the program should skip this step.
Is there a way to write the program in a way that it automatically does the correct thing?
Is there a function to check if an array exists?
typedef unsigned char cfg_u8;
typedef union {
struct {
cfg_u8 offset;
cfg_u8 value;
};
struct {
cfg_u8 command;
cfg_u8 param;
};
} cfg_reg;
const PROGMEM cfg_reg registers[] = {
{ 0x0D, 0x0C },
...
{ 0xFF, 0x00 },
}
Its a register header file created by a GUI of Texas Instruments.
Im looking for a way to know for the main program if the registers array exists or not.
I guess you'd need to #define a flag in the .h file and check for it in your main file with conditional compilation:
#ifdef ARRAY_FLAG
Do stuff with array here
#endif
BTW:
It's not a good idea to define variables in a .h file, they should just be declared there. Otherwise, you'll end up with multiple definitions if the .h file is #include(d) in more than one source file. It should also be declared as 'extern' in the .h file.