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

for(N = List->Head;N;N = N->Succ)

struct NODE{
    struct NODE Succ;
    struct NODE Prev;
};

struct LIST{
    struct NODE *Head;
    struct NODE *Tail;
    int count;
};

struct LIST *List;
struct NODE *N;

......
for(N = List->Head;N;N = N->Succ)
{
    ......
}
Compiler C51 changed value of List->Head because of the side effect of N = N->Succ.What can I do?

Parents
  • "List is placed in XDATA because I use the large memory model"

    Ok, but shouldn't N therefore be placed in xdata as well? Quoting from your map file above:

    02000000H SYMBOL XDATA --- List
    00000001H SYMBOL DATA --- N

    "N is used in code: "N = List->Head" and "N = N->Succ" in the for-loop"

    Yes, I must have been sleeping. Again.

    I think Hans is right, the optimisation is legitimately causing this. The order of events is (pseudocode):

    List=An address;
    N=List->Head;
    LABEL:
    N=N->Succ;
    if(N) goto LABEL

    So, List and N can occupy the same location without anything going wrong.

    Stefan

Reply
  • "List is placed in XDATA because I use the large memory model"

    Ok, but shouldn't N therefore be placed in xdata as well? Quoting from your map file above:

    02000000H SYMBOL XDATA --- List
    00000001H SYMBOL DATA --- N

    "N is used in code: "N = List->Head" and "N = N->Succ" in the for-loop"

    Yes, I must have been sleeping. Again.

    I think Hans is right, the optimisation is legitimately causing this. The order of events is (pseudocode):

    List=An address;
    N=List->Head;
    LABEL:
    N=N->Succ;
    if(N) goto LABEL

    So, List and N can occupy the same location without anything going wrong.

    Stefan

Children
No data