472,127 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

function name from function pointer

hi,
is it possible to get function name from function pointer. I am using
gcc compiler
on linux.

thanks
Nov 11 '08 #1
12 16201
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
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
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
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
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
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
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
>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
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
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
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
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.

Similar topics

1 post views Thread by QH Hong | last post: by
9 posts views Thread by cmk128 | last post: by
6 posts views Thread by Robbie Hatley | last post: by
5 posts views Thread by Gary Wessle | last post: by
15 posts views Thread by dspfun | last post: by
10 posts views Thread by Richard Heathfield | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.