Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: function name from function pointer

Reply
Thread Tools

Re: function name from function pointer

 
 
Alessandro Basili
Guest
Posts: n/a
 
      11-04-2010
On 11/3/2010 10:58 PM, Jorgen Grahn wrote:
> Judging from your three postings, you seem to believe you have a
> right to demand this functionality from the language. Let me humbly
> point out that most C programmers /don't/ want that feature, and
> you're unlikely to get it.
>


I must have erroneously under-evaluated the complexity of the problem,
and by no means I believe I have a right to demand anything.
The post was initiated when I bumped into this problem and started
looking around if somebody else had already had the same urge (i.e.
printing the name of a function knowing its pointer). As I can see it
now, is not such a common problem that would worth the effort of a
language implementation change.

> What are you trying to accomplish? Perhaps there is a solution to
> your problem which doesn't involve knowing the names of your
> functions.
>


I have implemented a state machine, using pointers to function for
states. The dispatcher provides events to the states and a change in the
state is simply accomplished changing the "state" pointer to yet another
function (the layout of the program can be found here:
http://www.netrino.com/Embedded-Syst...Driven-Systems,
in listing 1,2 and 3).

I found the approach quite nice and easily scalable to more complex
problems, without having the need to maintain any table (events, states)
or the burden of so many switch/case scattered around.

My problem though is that in this approach is not quite easy to print in
which state I am, since the state is represented only by the function
pointer. That is why I thought that having the possibility to get the
name of the function from its pointer would have helped me out.

> /Jorgen
>


 
Reply With Quote
 
 
 
 
Michael Angelo Ravera
Guest
Posts: n/a
 
      11-04-2010
On Nov 4, 1:52*am, Alessandro Basili <(E-Mail Removed)>
wrote:
> On 11/3/2010 10:58 PM, Jorgen Grahn wrote:
>
> > Judging from your three postings, you seem to believe you have a
> > right to demand this functionality from the language. Let me humbly
> > point out that most C programmers /don't/ want that feature, and
> > you're unlikely to get it.

>
> I must have erroneously under-evaluated the complexity of the problem,
> and by no means I believe I have a right to demand anything.
> The post was initiated when I bumped into this problem and started
> looking around if somebody else had already had the same urge (i.e.
> printing the name of a function knowing its pointer). As I can see it
> now, is not such a common problem that would worth the effort of a
> language implementation change.
>
> > What are you trying to accomplish? *Perhaps there is a solution to
> > your problem which doesn't involve knowing the names of your
> > functions.

>
> I have implemented a state machine, using pointers to function for
> states. The dispatcher provides events to the states and a change in the
> state is simply accomplished changing the "state" pointer to yet another
> function (the layout of the program can be found here:http://www.netrino.com/Embedded-Syst...chines-Event-D...,
> in listing 1,2 and 3).
>
> I found the approach quite nice and easily scalable to more complex
> problems, without having the need to maintain any table (events, states)
> or the burden of so many switch/case scattered around.
>
> My problem though is that in this approach is not quite easy to print in
> which state I am, since the state is represented only by the function
> pointer. That is why I thought that having the possibility to get the
> name of the function from its pointer would have helped me out.
>
>
>
> > /Jorgen- Hide quoted text -

>
> - Show quoted text -


If you have control over all of the functions about whose names you
care, it is very easy. You simply set a variable STATE to the current
state on the entry to each state function.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments