This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Import definitions/macros

Hello...

Currently I am using a header file that contains imported variables/functions/arrays at specific addressing. This is not ideal but it is the only workaround I have for my project. Now I'm trying to modularize my code therefore I am not able to include this header file in all modules as it will cause linker errors. I am using extern to get around that for var declarations. I was wondering if there is any way to import #define 's other than simply copying them over to each module. The following super rough code is to elaborate what I mean.

/* mem_import.h */
#ifndef MEM_IMPORT_H
#define MEM_IMPORT_H

volatile int flags _at_ 0;
#define flags_array ((uint8_t xdata *)(0x0080))
#define operate_flags() (*(void (code *)(void))(0x00ff))()

#endif

/* main.c */
#include "module_a.h"
#include "module_b.h"
#include "mem_import.h"


/* module_a.c */
// #include "mem_import.h"
extern volatile int flags;

/* module_b.c */
//#include "mem_import.h"
extern volatile int flags;

I would like to be able to use the 'operate_flags()' and 'flag_array' macros in each module. Is there any way to do this that doesn't involve including the mem_imports.h or simply copying it over where ever it's needed. The reason I don't want to copy it over is I will loose the modularization because of the specific addressing.

Thanks for any help in advance and let me know if more clarification is needed.