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 } /////////////////////////////////////////////
"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!