Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: How do I get the address of the current function? Message-ID: <3339@goanna.cs.rmit.oz.au> Date: 29 Jun 90 11:14:39 GMT References: <90Jun28.195353edt.19442@me.utoronto.ca> <1823@tkou02.enet.dec.com> <90Jun29.013400edt.20194@me.utoronto.ca> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 32 In article <90Jun29.013400edt.20194@me.utoronto.ca>, writer@me.utoronto.ca (Tim Writer) writes: > 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. The things you are guaranteed about function pointers are (1) every function has a definite unique "address" which is not NULL (2) "all function pointers smell the same" (3) given the address of a function, you can call it. That's about it. In particular, there is no reason to expect the "function address" used by C to be or to resemble any hardware address within the machine code generated for the function. C's "function pointer" might be any of the following: (a) An address near the beginning of the machine code (b) An address near the end of the machine code (c) An index into an array of addresses or ECBs (d) The (data) address of an Entry Control Block (Apollo, PR1ME) (e) The address of an instruction which is initially a trap, and then gets overwritten by a jump to dynamically loaded code (f) The address of a location somewhere in the literal pool for a function (IBM RT PC) ... If the C compiler you're using goes in for literal pools, you may be in luck. The address of the literal pool is likely to be around in a register. I don't know whether SPARC compilers do this. It's important to realise that you have *two* problems: -- how does this COMPILER represent a function pointer? -- how do I get one of those at run-time on this HARWARE? -- "private morality" is an oxymoron, like "peaceful war".