By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,945 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,945 IT Pros & Developers. It's quick & easy.

function name from function pointer

P: n/a
hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.

thanks
Nov 11 '08 #1
Share this Question
Share on Google+
12 Replies


P: n/a
sinbad wrote:
hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C. Try a Linux group, or comp.unix.programmer.

--
Ian Collins
Nov 11 '08 #2

P: n/a
On 11 Nov 2008 at 6:15, sinbad wrote:
is it possible to get function name from function pointer. I am using
gcc compiler on linux.
Yes: man dladdr. You'll probably need to give gcc the -rdynamic flag to
get the linker to export a full symbol table.

Nov 11 '08 #3

P: n/a
On Nov 11, 3:46*pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 11 Nov 2008 at *6:15, sinbad wrote:
is it possible to get function name from function pointer. I am using
gcc compiler on linux.

Yes: man dladdr. You'll probably need to give gcc the -rdynamic flag to
get the linker to export a full symbol table.
Hi,
You can print the function pointers address using %pf and then look
up for the same in the object table given by nm.
HTH,

Deepak.P
Nov 11 '08 #4

P: n/a
Ian Collins wrote, On 11/11/08 06:23:
sinbad wrote:
>hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C.
That should be sometimes.
Try a Linux group, or comp.unix.programmer.
Indeed.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 11 '08 #5

P: n/a
Peerless wrote, On 11/11/08 18:28:
On Nov 11, 3:46 pm, Antoninus Twink <nos...@nospam.invalidwrote:
>On 11 Nov 2008 at 6:15, sinbad wrote:
>>is it possible to get function name from function pointer. I am using
gcc compiler on linux.
Yes: man dladdr. You'll probably need to give gcc the -rdynamic flag to
get the linker to export a full symbol table.

Hi,
You can print the function pointers address using %pf and then look
up for the same in the object table given by nm.
Except when the name is not there. Ask in a Linux or Unix group for why
it might not be there on a Linux or Unix like system.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 11 '08 #6

P: n/a
Peerless wrote:
On Nov 11, 3:46 pm, Antoninus Twink <nos...@nospam.invalidwrote:
>On 11 Nov 2008 at 6:15, sinbad wrote:
>>is it possible to get function name from function pointer. I am using
gcc compiler on linux.
Yes: man dladdr. You'll probably need to give gcc the -rdynamic flag to
get the linker to export a full symbol table.

Hi,
You can print the function pointers address using %pf and then look
up for the same in the object table given by nm.
"%pf"? Is this like the "%du" from a few days ago?

As far as I know, there is no printf() conversion specifier
for function pointers. If there were one, it could not be "%pf",
nor "%fp" for that matter.

--
Er*********@sun.com
Nov 11 '08 #7

P: n/a
sinbad wrote:
>
is it possible to get function name from function pointer. ...
No.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 11 '08 #8

P: n/a
>is it possible to get function name from function pointer. I am using
>gcc compiler
on linux.
Two words: lookup table. Make a table of function names and their
addresses. Find a function pointer that matches the one you are
looking for, then use the corresponding name. It's very portable.
It also requires you to have a list of functions that are of interest
to make the table.

There are some system-specific ways to access symbols in an executable.
This is problematic because (1) there is no guaranteed way to find
the path of the running executable (some versions of Linux provide
a way to open it anyway), and (2) the executable, especially if
static-linked, might not *HAVE* any symbols. If it's code you are
compiling, you can usually arrange to keep the symbols.
Nov 12 '08 #9

P: n/a
On Tue, 11 Nov 2008 19:23:06 +1300, Ian Collins <ia******@hotmail.com>
wrote in comp.lang.c:
sinbad wrote:
hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C. Try a Linux group, or comp.unix.programmer.
Well, not prior to C99. Since then, there's:

"6.4.2.2 Predefined identifiers

Semantics

1 The identifier _ _func_ _ shall be implicitly declared by the
translator as if, immediately following the opening brace of each
function definition, the declaration
static const char _ _func_ _[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing
function.

2 This name is encoded as if the implicit declaration had been written
in the source character set and then translated into the execution
character set as indicated in translation phase 5."

Of course C99 implementations are pretty rare.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 12 '08 #10

P: n/a
Jack Klein wrote:
On Tue, 11 Nov 2008 19:23:06 +1300, Ian Collins <ia******@hotmail.com>
wrote in comp.lang.c:
>sinbad wrote:
>>hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C. Try a Linux group, or comp.unix.programmer.

Well, not prior to C99. Since then, there's:

"6.4.2.2 Predefined identifiers

Semantics

1 The identifier _ _func_ _ shall be implicitly declared by the
translator as if, immediately following the opening brace of each
function definition, the declaration
static const char _ _func_ _[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing
function.
So how would that help get a function name from a function pointer?

--
Ian Collins
Nov 12 '08 #11

P: n/a
Jack Klein wrote:
On Tue, 11 Nov 2008 19:23:06 +1300, Ian Collins <ia******@hotmail.com>
wrote in comp.lang.c:
>sinbad wrote:
>>hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C. Try a Linux group, or comp.unix.programmer.

Well, not prior to C99. Since then, there's:

"6.4.2.2 Predefined identifiers

Semantics

1 The identifier _ _func_ _ shall be implicitly declared by the
translator as if, immediately following the opening brace of each
function definition, the declaration
static const char _ _func_ _[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing
function.
Notice that __func__ behaves as if it were declared "immediately
following the opening brace", and therefore has block scope. It has to
have block scope, because if it had file scope its definition would
conflict with the definition of __func__ in all of the other functions
of the program. Therefore, the only __func__ that can be referred to
directly by any given function is that function's own __func__. How are
you suggesting that this feature be used to determine the name of some
other function, using only a pointer to that other function?
Nov 12 '08 #12

P: n/a
Jack Klein <ja*******@spamcop.netwrites:
On Tue, 11 Nov 2008 19:23:06 +1300, Ian Collins <ia******@hotmail.com>
wrote in comp.lang.c:
>sinbad wrote:
hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.
Yes, but not in standard C. Try a Linux group, or comp.unix.programmer.

Well, not prior to C99. Since then, there's:

"6.4.2.2 Predefined identifiers

Semantics

1 The identifier _ _func_ _ shall be implicitly declared by the
translator as if, immediately following the opening brace of each
function definition, the declaration
static const char _ _func_ _[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing
function.

2 This name is encoded as if the implicit declaration had been written
in the source character set and then translated into the execution
character set as indicated in translation phase 5."

Of course C99 implementations are pretty rare.
The __func__ feature, however, is not so rare, in my experience. But
how does it help you get the function name given a *function pointer*?

Nov 12 '08 #13

This discussion thread is closed

Replies have been disabled for this discussion.