473,788 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17263
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.progr ammer.

--
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.progr ammer.
Indeed.
--
Flash Gordon
If spamming me sent it to sm**@spam.cause way.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.cause way.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******@hotma il.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.progr ammer.
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.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 12 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1503
by: QH Hong | last post by:
Hi, I have several classes and several members. class c1, c2, c3,... member of class c1 is m11, m12,... member of class c2 is m21, m22,... Each member takes one argument (double type) and returns double value. I have a function which takes the function name and
1
3174
by: DMamoun | last post by:
I am trying to call a fuction a a C# dll using the GetProcAddress, but the returned handle is null, wheras the LoadLibrary of the container dll succeeds, I write the function name as it is written in ducumentaion, I tried to use dumpin, but it doesn't show any method name. what does this mean and how I can call this fucntion
9
5088
by: cmk128 | last post by:
Hi Why put * in front of the function name in the declaration? int (*write)(struct inode *, struct file *, const char *, int); thanks from Peter (cmk128@hotmail.com)
6
3496
by: Robbie Hatley | last post by:
I just ran across this code at work: BOOL main_AddDefaultBenchHeaterPeriods // ??? ( DWORD main_AddDefaultBenchHeaterPeriods // ??? ) { // ... two dozen lines of code ...
5
6614
by: Gary Wessle | last post by:
Hi is there a way to convert a string to a function name and fire it. like void his_fun(){ cout << "his is here" << endl; } vector<stringvec; vec.push_back("his");
15
22864
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which could either be f1() or f2(). BRs!
7
8437
by: dries | last post by:
Hello lads, I'd like to do the following in C: 1. The user writes a function with predefined arguments and return value in a separate file. 2. The program is compiled as my written 'main' program and the file containing the user function included. 3. When the program is invoked, the user is asked how his function is named (f.e. function1). 4. The 'main' program calls and executes the user function. The problem is, how can I cast the...
10
3620
by: Richard Heathfield | last post by:
Stephen Sprunk said: <snip> Almost. A function name *is* a pointer-to-function. You can do two things with it - copy it (assign its value to an object of function pointer type, with a cast if necessary but preferably to one of the /right/ function pointer
1
1566
by: Nitin | last post by:
Hi, Can I devise function pointer type from function name by using template programming? e.g. I have function: exertn “C” void xmlFreeDoc(xmlDocPtr cur); I want something like following: typeof(xmlFreeDoc) functionpointer = xmlFreeDoc; i.e value to type conversion
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.