Hello, Suppose you declare an array in a certain memory space, for instance
unsigned char xdata SendBuffer[ 20 ];
byte *SendBuffer
TempVal = *( SendBuffer + Counter );
TempValue = *( (unsigned char xdata*)SendBuffer + Counter );
idata
Keil C51 uses a "tagged" representation for a pointer to an unspecified memory space. Let's call that a "generic" pointer. The generic pointer has two bytes of address, plus one byte of "tag" that tells the code whether the address is in code space, xdata space, data space, and so on. If you declare the pointer with a particular memory space specified, the pointer will only take up two bytes, and you code gets a little more efficient.
char* SendBuf; // 3-byte pointer char xdata* SendBuf; // 2-byte pointer
// passes 3-byte pointer in R1-R3 void MyFunc (char* SendBuf); // can't pass 2 generic pointers in registers void MyFunc2 (char* dst, char* src); // passes 2-byte pointer in R6/R7 void MyFunc (char xdata* SendBuf); // passes pointers in R4/R5 and R6/R7 void MyFunc2 (char xdata* dst, char xdata* src);
"you'll get more efficient code by using specific pointers" That depends upon your definition of "efficient" If you use Generic Pointers, the compiler will use Library calls to handle them; if you use memory-specific pointers, the compiler can put the code in-line. Thus, using memory-specific pointers can actually increase your code size - although execution speed should be improved. As I said, it all depends on what you mean by, "efficient"
This is why the compiler has an option for the optimizer to favor speed or to favor space :)