I am trying to come up with a method for defining absolute (MMIO) addresses once in my universal .h file. DATAACT id defined in one .c file only UX* is xdata unsigned char My attempt:
#ifdef DATACT #define UXRG(name,addr) UX8 name _at_ addr; #else #define UXRG(name,addr) extern UX8 name; #endif used as UXRG (XRleds, 0xff00);
Normally, I would put the extern reference into the .h file, and put the actual definition into the .c file (the one where you would define DATACT). No macros needed.
Normally, I would put the extern reference into the .h file, and put the actual definition into the .c file (the one where you would define DATACT). No macros needed. That is fine for small projects with no changes; however, with that method every change has to be made in 2 places and will get screwed up. Erik
That looks pretty similar to the following: http://www.keil.com/support/docs/1868.htm And it seems like a good way to go to me. At least, it's similar to what I've done in the past. Jon
It is, indeed, similar and works well my way and as shown in Jons reference; however, the question is how to include the _at_ in this technique Erik
I've used that method on projects as large as about 1.2 million lines with no problems. (Not for an 8051 of course!) After all, you don't (or shouldn't) directly reference global variables very often, particularly in a sizeable project. If you forget to change one of the places, the compiler (and lint, and the linker) will immediately remind you, as you'll have mismatched types, unresolved symbols, and so on. You'll still have to make the change in two places, albeit two that are a lot closer together, and at the cost of an extra level of macro obscuration in the source. But whatever you prefer; seems like you like your original method. (If you didn't actually want suggestions for alternatives, why ask for them?)
(If you didn't actually want suggestions for alternatives, why ask for them?) I am not asking for "alternatives", I am asking "how do I expand my (and other peoples) method to include _at_ xdata" Erik
You need to get rid of the trailing semicolon at the end of the #define line. Stefan
You need to get rid of the trailing semicolon at the end of the #define line. none there, copy to forum error Erik
You say you need to change that trick for the case of _at_ --- but I don't see any reasons why you think it wouldn't just work, as it is. I'm not entirely positive on this (read: I haven't actually tried it), but as far as I can see, for an _at_ definition, the whole point of the separation between definition and declaration is moot anyway. I.e. I'd just have
type var _at_ addr;