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.
As I mentioned this was just rough code to make my point. This is in no way the actual code or the absolute addresses used.
I understand where externs should be used. The header mentioned is exported from another project so I cannot directly make changes to it. I was just trying to work around what I was dealt with, and after reading your comments I have made requests for changes in the other project. Thanks for your time.
Then whoever is responsible for that export should be shot!
As already noted, doing it in your own project is bad enough - but exporting it to anyone else's project is unforgivable!