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
  • You were looking for the wrong kind of symptoms, then.

    The fact that two variables end up being placed in the same address, all by itself, tells you exactly nothing about the actual behaviour of the program. The compiler is perfectly allowed to re-use the memory positions used for 'List' to store something else in it after 'List' itself is no longer used. That's what the word "optimization" in "optimization level 8" is mainly about, after all.

    Without this kind of tricks, it would be close to impossible to fit any decent-sized C program into a typical 8051 device --- there simply isn't enough memory space to spare.

Reply
  • You were looking for the wrong kind of symptoms, then.

    The fact that two variables end up being placed in the same address, all by itself, tells you exactly nothing about the actual behaviour of the program. The compiler is perfectly allowed to re-use the memory positions used for 'List' to store something else in it after 'List' itself is no longer used. That's what the word "optimization" in "optimization level 8" is mainly about, after all.

    Without this kind of tricks, it would be close to impossible to fit any decent-sized C program into a typical 8051 device --- there simply isn't enough memory space to spare.

Children
No data