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

Data Space grows unexpectedly

Hi all,
I've noticed something strange with one of
my 8051 projects. When I build the project, the build results show that I have used 98 bytes of data space. If I add the statement while(1) {} to the beginning of main(), my data space useage goes up to 161!, which is too much to fit in my SiLabs MCU.
If I move the while(1) statement down further in main(), the data useage starts getting less, until it reaches the original 98 when the while statement is placed at the very end of main(). Also, the statement while(0) {} does not cause any change in the data space useage value, regardless of where it is placed.

What is causing this wierd behaviour?

Thanks for all your help.
Tony

Parents
  • The while(1) will cut off potentially many function calls from the call tree:

    A();
    while (1);
    B();
    C();
    D();

    B, C, and D will thus become roots of their own call tree, and any data memory needed by those call trees cannot be overlaid with that of the one with root at main (or A).

    while(0) does not have this effect, because it does not prevent the flow of control from reaching the later functions.

    The optimizer will eliminate the calls to B, C, D. But the linker will have to eliminate the body of those functions. Either each function must be in its own C file (so that each winds up in its own segment) for the linker to omit the unneeded functions, or the new REMOVEUNUSED directive must be used with the linker to get rid of the uncalled code.

Reply
  • The while(1) will cut off potentially many function calls from the call tree:

    A();
    while (1);
    B();
    C();
    D();

    B, C, and D will thus become roots of their own call tree, and any data memory needed by those call trees cannot be overlaid with that of the one with root at main (or A).

    while(0) does not have this effect, because it does not prevent the flow of control from reaching the later functions.

    The optimizer will eliminate the calls to B, C, D. But the linker will have to eliminate the body of those functions. Either each function must be in its own C file (so that each winds up in its own segment) for the linker to omit the unneeded functions, or the new REMOVEUNUSED directive must be used with the linker to get rid of the uncalled code.

Children