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

Function pointers

Hello all,
We have a strange problem. During execution of a function, the control goes to some different line in a different function, without making a call it... I will try to explain the scenario with an example....

Say we have a function A (30 lines) and a function B (say 30 line too).
During the execution of the function A, say it is in line 18, it jumps to some line (say 23) in function B.....No call is made to function B in function A. And this happens exactly at the same line everytime we run the program. There are no calls to any function in A....just some calculations, some if statements...etc. No function calls in A.

We have some function pointers in our program, we have read the related documents in the keil knowledge base. We have added the necessary linker settings, to modify the linker call graph.

So as far as the settings are concerned, we have made all the linker settings and confirmed it with the resulting MAP file. The call graphs is as expected....

Can there be any other reasons for the cotrol to jump in the above manner...???

Code size is well below 64K, so we are not using code banking.

regards
prasanna

Parents
  • Which 'asm' exactly did you look at? For this to be meaningful, it'd have to be the disassembly inside the debugger, and you'ld have to F11 through that, at the critical location. My guess is you're just seeing the effect of OT(9) (common block subroutines), i.e. equivalent code in your two functions was noticed by the compiler and turned into a single subroutine. Trying to debug that kind of compiled code at source level is not likely to work well.

Reply
  • Which 'asm' exactly did you look at? For this to be meaningful, it'd have to be the disassembly inside the debugger, and you'ld have to F11 through that, at the critical location. My guess is you're just seeing the effect of OT(9) (common block subroutines), i.e. equivalent code in your two functions was noticed by the compiler and turned into a single subroutine. Trying to debug that kind of compiled code at source level is not likely to work well.

Children
  • >>>Which 'asm' exactly did you look at? For this to be meaningful, it'd have to be the disassembly inside the debugger,


    It was the asm in the disassembly insided the debugger.....as i mentioned earlier, it does show the next instruction which is the actual next line in the function, but when i do a F11, it jumps to the other function....

    During debugging i also tried to use the yellow arrow mark, which is used to show"next instruction", which points to the actual next instruction in the function. But F11 takes it to the other function....

    regards

  • this is as it should be

    let us say you have 2 functions
    func1
    X: do a
    Y: do b
    Z: do c
    return

    and func2
    P: do d
    Q: do e
    R: do c
    return

    the optimizer will change func1 as follows:
    func1
    X: do a
    Y: do b
    GOTO r:

    which saves codespace.

    Erik

  • Not exactly....i mean....the Func1 is actually a routine to write on the SMBus. I am using C8051F130....

    And the function where it is jumping to, is the Port initialization function, were we are initialization the ports, the crossbar, emif....etc.

    There is nothing common in between Function 1 and Function 2.....

    regards
    prasanna