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

Local varible in same address

Hi All

I write a function like this

test.c
void a(U8 val)
{ U8 ch=0;

dev[ch].fun1(val); <--this is a function pointer , it will call the b function

dev[ch].fun2(val); <--Fail here
}

void b( U8 val)
{ U8 dummy = val *5;

writeReg[0x55AA]= dummy;
}

after run the " dev[ch].fun1(val)"

The ch varible will be change , so it will fail when run " dev[ch].fun2(val)"

I found the varible is in the same memory address, How can I avoid it??

and how can I know the memory map of all local varible ??

I found the m51 file , the data is map to 18h to 28h

DATA 0018H 0028H UNIT ?DT?TEST

why ch varible is map to 0x40 and same as dummy varible??

Thanks for you kindly help and sorry for my poor english

Parents Reply Children
  • Just spotted this:

    void a( U8 val )
    {
       U8 ch=0;
    
       dev[ch].fun1(val); <--this is a function pointer, it will call the b function
    
       dev[ch].fun2(val); <--Fail here
    }
    

    The Overlaying means that you have to be very careful how you use function pointers in Keil C51 - if you use them at all.

    You must read this: http://www.keil.com/appnotes/docs/apnt_129.asp
    - and follow its directions carefully!

  • Andrew Neil ,Thanks a lot

    but I still don't know how to use the key word [overlay] correctly

    I just use " ?PR?A?Test!* " in BL51 Misc to fix this

    In my code , Do I need to write Overlay (?PR?A?TEST ~ ?PR?B?TEST )??

    Thanks again for your kindly help

  • Then you're going to have to keep researching & studying documentation until you do!

    There's a lot of other information - App Notes, knowledgebase articles, etc - I gave some links in the thread I mentioned earlier.

    Alternatively, perhaps you should take a hint that this is not something for which the 8051 is well-suited - and either restructure your application in a way that's more appropriate to the target, or choose a different target that's more appropriate to this kind of thing...