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
  • Or a little bit shorter:

    
    void foo1(void);
    void foo2(void);
    
    void (*function_pointer)(void) = &foo1;
    
    
    void foo1(void)
    {
      function_pointer = &foo2;
    }
    
    void foo2(void)
    {
      //linker warning comes with definition of this variable
      //Without this variable or if the variable is static, no warning occurs
      char var;
      function_pointer =&foo1;
    }
    
    void main()
    {
       (*function_pointer)();
    }
    

    Output is:

    Build target 'Target 1'
    compiling main.c...
    MAIN.C(17): warning C280: 'var': unreferenced local variable
    linking...
    *** WARNING L13: RECURSIVE CALL TO SEGMENT
        SEGMENT: ?PR?FOO1?MAIN
        CALLER:  ?PR?FOO2?MAIN
    Program Size: data=13.0 xdata=0 code=182
    "function_pointer_test" - 0 Error(s), 2 Warning(s).
    

Reply
  • Or a little bit shorter:

    
    void foo1(void);
    void foo2(void);
    
    void (*function_pointer)(void) = &foo1;
    
    
    void foo1(void)
    {
      function_pointer = &foo2;
    }
    
    void foo2(void)
    {
      //linker warning comes with definition of this variable
      //Without this variable or if the variable is static, no warning occurs
      char var;
      function_pointer =&foo1;
    }
    
    void main()
    {
       (*function_pointer)();
    }
    

    Output is:

    Build target 'Target 1'
    compiling main.c...
    MAIN.C(17): warning C280: 'var': unreferenced local variable
    linking...
    *** WARNING L13: RECURSIVE CALL TO SEGMENT
        SEGMENT: ?PR?FOO1?MAIN
        CALLER:  ?PR?FOO2?MAIN
    Program Size: data=13.0 xdata=0 code=182
    "function_pointer_test" - 0 Error(s), 2 Warning(s).
    

Children