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 code reference error

Hello ALL!

I would ask the next question...

according http://www.keil.com/support/docs/2379.htm

one must manually remove the reference between func2 and the ?CO?EXAMPLE1 segment and add MAIN ! FUNC2 reference between MAIN and FUNC2.
But from App129 if I define
code void (*func_array[])() = { func2 };
with the storing table in code space, I will get the correct call tree.

Now is a question: if I would not make this overlay command like sad in the
http://www.keil.com/support/docs/2379.htm
bl51 EXAMPLE1.OBJ IX OVERLAY & (?CO?EXAMPLE1 ~ FUNC2, MAIN ! FUNC2)

would I have any problem?

How I understood it's harmless because there are no actual recursive calls in the code, just a reference from one item in the constant segment to another.

Could somebody please make it a little bit more clear for me?

Thank you very much,
A.

Parents
  • It would be very interesting to see how this code can fail(without big changes and with function pointers table stored in the code space )...

    Very well. The following code (which is a very slight modification of yours) generates the exact same warning and call tree.

    void func1 (unsigned char *msg);
    void func2 (void);
    
    code void (*func_array[])() = { func2, };
    
    
    void func1 (unsigned char *msg) {
    ;
    }
    
    void func2 (void) {
    int b = 4;
    int c = 5;
    
    (*func_array[0])();
    func1("xxxxxxxxxxxxxxx");
    }
    
    void main (void) {
    int a = 5;
    (*func_array[0])();
    
    while (1);
    }
    

    And...It fails.

    The problem is that your test program is so trivial that it does not stress the design, the implementation, the tools, or anyone's brain. In fact, most of the operations are just plain nonsense. In such cases, it is ALWAYS possible to get something to work because it's not doing anything.

    Jon

Reply
  • It would be very interesting to see how this code can fail(without big changes and with function pointers table stored in the code space )...

    Very well. The following code (which is a very slight modification of yours) generates the exact same warning and call tree.

    void func1 (unsigned char *msg);
    void func2 (void);
    
    code void (*func_array[])() = { func2, };
    
    
    void func1 (unsigned char *msg) {
    ;
    }
    
    void func2 (void) {
    int b = 4;
    int c = 5;
    
    (*func_array[0])();
    func1("xxxxxxxxxxxxxxx");
    }
    
    void main (void) {
    int a = 5;
    (*func_array[0])();
    
    while (1);
    }
    

    And...It fails.

    The problem is that your test program is so trivial that it does not stress the design, the implementation, the tools, or anyone's brain. In fact, most of the operations are just plain nonsense. In such cases, it is ALWAYS possible to get something to work because it's not doing anything.

    Jon

Children
  • Jon,
    ok, but in this case you have a real recursion(the function calls itself, what I wanted avoid in case if I don't use overlay) and the only one way to make this program running is using of reentrant functions.

    With best regards,
    A.