Path: utzoo!utgpu!news-server.csri.toronto.edu!me!writer Newsgroups: comp.lang.c From: writer@me.utoronto.ca (Tim Writer) Subject: Re: How do I get the address of the current function? Message-ID: <90Jun29.013400edt.20194@me.utoronto.ca> Organization: University of Toronto, Department of Mechanical Engineering References: <90Jun28.195353edt.19442@me.utoronto.ca> <1823@tkou02.enet.dec.com> Date: 29 Jun 90 05:34:15 GMT In article <1823@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >In article <90Jun28.195353edt.19442@me.utoronto.ca> writer@me.utoronto.ca (Tim Writer) writes: >If you know the name of the function, if it is foo, you just say &foo I don't want to need to know the name of the function. >void (*fcn)(); >void foo() { > fcn = &foo; >} Actually, it would just be `fcn=foo'. As I feared, you misunderstood me. I want to *compute* the address of the currently executing function. In other words, I want the computer to tell me what is the address of the function it is executing. Consider the following pseudocode. 1 jmp_buf buf1, 2 buf2, 3 buf3; 4 5 main() 6 { 7 if (setjmp(buf1)) { 8 ... stuff ... 9 longjmp(buf3,1); 10 } 11 ... stuff ... 12 fcn() 13 ... stuff ... 14 } 15 16 fcn() 17 { 18 if (setjmp(buf2)) { 19 ... stuff ... 20 longjmp(buf3,1); 21 } 22 ... stuff ... 23 if (... condition ...) { 24 void setjmp(buf3); 25 longjmp(... buf1 or buf2, I don't know ...,1) 26 } 27 ... stuff ... 28 } Longjmp() on line 25 may jump to line 19, or it may jump to line 8; I don't know which. If it jumps to line 19, longjmp() on line 19 is fine. However, if it jumps to 8, the longjmp() on line 9 would be jumping into fcn() which has returned. The problem is how to detect this. I have a written a fairly general exception handling facility which includes several macros which generate code similar to the above. That is why I don't know where the longjmp() of line 25 is going to jump to. When I use these macros I want them to be able to detect a bad longjmp() without needing to pass them extra arguments which differ from function to function. I figured if there was a way to compute the address of the currently executing function, I could have my macros set and examine a global function pointer. So, before line 25, I would set it, and I would check it against the address of the currently executing function before lines 9 and 20. That way, I could tell where the longjmp() was going to go. I hope this makes things a bit more clear. Any suggestions? Tim