This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

General Question Re: Memory Models and Abstract Pointers

Hi All.

I'm becoming more familiar with C51's various memory models, but I could use some confirmation on one issue.

Here's a code snippet:

char CODE_B = 'B';
char CODE_C = 'C';

...

void TaskShow( void )
{
    OStypeMsgP msgP;
    
    InitPORT();
    PORT = 0x00;
    
    for (;;) {
        OS_WaitMsg(MSG_UPDATE_PORT_P, &msgP, OSNO_TIMEOUT, TaskShow1);
        
        if ( *(char *)msgP == CODE_C ) {
            PORT &= ~0xFE;
            PORT |= ( counter >> 8 ) & 0xFE; 
        }
        else
            PORT ^= 0x01; 
    }
}

where OStypeMsgP is void *.

For the SMALL memory model, this code works fine. For the LARGE memory model (with variables in XDATA), I must change the line that dereferences the pointer to
if ( *(char xdata *)msgP == CODE_C ) {

Makes sense to me ...

1) Could someone just verify that this is the intended behavior of variables that do not have an explicit memory type? I.e. if I do not add an explicitly declared memory type (e.g. data|xdata|idata|pdata|...) to the variable's declaration, then will it automatically be in the selected memory model's default memory area?

2) From what I can see, this means that "abstract pointers" are always of type void *, and one must simply dereference them properly, using the explicitly declared memory type in the dereferencing cast. Correct?

Thanks,

0