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

Recursive Call Warning? Why?

Hi,

please can someone try this little code snippet with the C51 compiler and tell me why I am getting a "Linker Warning L13: Recursive Call to Segment Foo1, Caller: Foo2"

void foo1(void);
void foo2(void);

void (*function_pointer)(void) = &foo1;


void set_function(void(*p_function_pointer)(void))
{
  function_pointer = p_function_pointer;
}

void execute(void)
{
  (*function_pointer)();
}

void foo1(void)
{
  set_function(&foo2);
}

void foo2(void)
{
  bit Linker_Warning_Comes_With_Definition_Of_This_Bit;
  set_function(&foo1);
}

void main()
{
   execute();
}

Parents
  • The linker isn't executing the code. But in this case, it sees that the two functions contains references to each other. That you don't actually make the call is probably outside the scope of the linker to notice.

    Anyway - the 8051 is not an architecture where you should design your programs around function pointers. The compiler/linker needs to do huge amounts of tricks to try to make best use of the HLL-unfriendly processor. Function pointers are doing their best to make it hard for the compiler/linker to know who calls what, to evaluate the full call trees.

Reply
  • The linker isn't executing the code. But in this case, it sees that the two functions contains references to each other. That you don't actually make the call is probably outside the scope of the linker to notice.

    Anyway - the 8051 is not an architecture where you should design your programs around function pointers. The compiler/linker needs to do huge amounts of tricks to try to make best use of the HLL-unfriendly processor. Function pointers are doing their best to make it hard for the compiler/linker to know who calls what, to evaluate the full call trees.

Children