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

Trouble accessing array values

I'm having difficulty accessing a value from an array. Here's an example of what the code is doing:

unsigned char xdata In_Buf[2][70];
unsigned char port;

void main(void){

port = In_Buf[0][0];

.
.
}


port never updates no matter what the value of the first array element.

Anyone have a suggestion?

  • Paul,

    I don't seen anything obvious in the code you posted. Perhaps a more complete (but small) sample would help. I'm thinking that it might relate to how port is being used (could it be that it is getting optimised).

    How do you know post never gets updated? have you looked at the resultant assembly code?

    Regards,
    Steven

  • Steven,

    I think I found a possible issue that caused the symptoms I saw - a variable name was used in a function and later was duplicated as a global. No warning about variable redefinition was given, but this error apparently causes the compiler and/or linker to do some really strange things. A careful reading of the map file uncovered the problem. Now that the variables have been corrected things are much more predictable.

    Thanks for your help!

    Paul

  • maybe not strange. There are specific C rules about what happens when There are locals and globals with the same name. Lookup "Variable Scope"

  • "There are specific C rules about what happens when There are locals and globals with the same name."

    It's not just 'C' - most block-structured high-level languages (HLL) have similar rules.

    It's a bit like the way you can have many fies on your hard drive all with the same name - you distinguish between them by knowing which folder (directory) each one is in...

  • just a will goess
    if 'port' is a rename of SBUF, what you see ios correct

    Erik