We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, it seems that using "_at_" keyword with extern variables does not work well. The code below shows what I wish to share with you guys.
///////////////////////////////////////////// sample.c: xdata volatile unsigned char xdata_var_bad _at_ 16; xdata volatile unsigned char xdata_var_ok _at_ 16; void test( void ) { xdata_var_bad = 0; xdata_var_ok = 0; } ///////////////////////////////////////////// ///////////////////////////////////////////// sample.h: extern xdata volatile unsigned char xdata_var_bad _at_ (16); extern xdata volatile unsigned char xdata_var_ok; ///////////////////////////////////////////// ///////////////////////////////////////////// main.c: #include "sample.h" void main(void) { xdata_var_bad =0; // disassembly for above assignment is: // MOV DPTR,#0x0000 // MOV A,#0 // MOVX @DPTR,A xdata_var_ok =0; // disassembly for above assignment is: // MOV DPTR,#0x0010 // MOV A,#0 // MOVX @DPTR,A } /////////////////////////////////////////////
Now I saw that in the help is writen how to use extern declaration with _at_ keyword. but, there isn't noted side effect when using variable declaration that combine "extern" with "_at_". Boris
Think about it: The _at_ keyword can only apply to a variable's definition, can't it? _at_ is pointless with an 'extern' declaration!
In my opinnion, seems to me that, using "_at_" with "extern" for external variable usage should be pointless - or sould I say "fully pointless". Many of us programmers like to copy variable declaration from .c to .h file - so there is probability that _at_ keyword with absolute memory storage address is also pasted. Altrough, in the help is noted how to use _at_ for extern variable reference... but there is not noted that using it like I was doing will produce wrong reference. That is why I posted description of non-documented compiler behavior, to avoid that other programmers go my way. And, I like to see one new compiler warning message in future release of my favorite IDE for u-controllers ;-) Boris
"Many of us programmers like to copy variable declaration from .c to .h file" When you do that, you have to remove any initialisations, don't you? Removing any _at_ keywords is just the same! Remember: the thing in the .c file is a definition; the thing in the .h file is a declaration - understanding the distinction is key to understanding what's going on here!