473,799 Members | 2,693 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
12 17268
Jack Klein wrote:
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.
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******@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.
Notice that __func__ behaves as if it were declared "immediatel y
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*******@spam cop.netwrites:
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.
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 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
5089
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
6615
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
22870
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
3624
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
1567
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
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
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
10269
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
10032
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
9085
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...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4148
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
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.