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 (see message)...

    "N is never used in the code hence it doesn't matter where it is placed:
    "

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

    In small model I get the following map-file:

          VALUE       REP       CLASS    TYPE      SYMBOL NAME
          ====================================================
          ---         MODULE    ---      ---       MAIN
          01000003H   PUBLIC    CODE     ---       main
    
          01000003H   BLOCK     CODE     ---       LVL=0
          01000003H   BLOCK     CODE     NEAR LAB  LVL=1
          00000008H   SYMBOL    DATA     ---       List
          00000001H   SYMBOL    DATA     ---       N
          ---         BLOCKEND  ---      ---       LVL=1
          ---         BLOCKEND  ---      ---       LVL=0
    
    N and List are still on different locations! The compiler generates code for the for-loop (optimization level 8!)

    Maybe a compiler/linker version problem?

    My versions are:
    C51: V7.06
    LX51: V3.58d
    (AX51: V2.09)

Reply
  • List is placed in XDATA because I use the large memory model (see message)...

    "N is never used in the code hence it doesn't matter where it is placed:
    "

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

    In small model I get the following map-file:

          VALUE       REP       CLASS    TYPE      SYMBOL NAME
          ====================================================
          ---         MODULE    ---      ---       MAIN
          01000003H   PUBLIC    CODE     ---       main
    
          01000003H   BLOCK     CODE     ---       LVL=0
          01000003H   BLOCK     CODE     NEAR LAB  LVL=1
          00000008H   SYMBOL    DATA     ---       List
          00000001H   SYMBOL    DATA     ---       N
          ---         BLOCKEND  ---      ---       LVL=1
          ---         BLOCKEND  ---      ---       LVL=0
    
    N and List are still on different locations! The compiler generates code for the for-loop (optimization level 8!)

    Maybe a compiler/linker version problem?

    My versions are:
    C51: V7.06
    LX51: V3.58d
    (AX51: V2.09)

Children
  • "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