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.
What, exactly, are you "working around" ?!
"I am not able to include this header file in all modules as it will cause linker errors"
That's exactly why you should not have definitions in header files!
c-faq.com/.../decldef.html
"I will loose the modularization because of the specific addressing"
So why have it in a header file?
The definition (which includes the absoltue addressing) should be in a .c file; only the extern declaration should be in the header.
Thanks Andrew. The problem was that the header is being created and exported from another project and it is certainly not the ideal, or honestly proper way of coding. I am aware of the difference between definitions and declarations, and where they should be located.
Sometimes you have to work with what you are dealt with. I have put in the request for the necessary changes... I was simply wondering if there is work around. Thanks for your time.