Re: function name from function pointer

Discussion in 'C Programming' started by Alessandro Basili, Nov 4, 2010.

  1. 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-Systems/How-To/State-Machines-Event-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
    >
     
    Alessandro Basili, Nov 4, 2010
    #1
    1. Advertising

  2. On Nov 4, 1:52 am, Alessandro Basili <>
    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-Systems/How-To/State-Machines-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.
     
    Michael Angelo Ravera, Nov 4, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    745
    Chris Torek
    Feb 4, 2005
  2. jimjim
    Replies:
    16
    Views:
    876
    Jordan Abel
    Mar 28, 2006
  3. Replies:
    4
    Views:
    1,332
    Fred Zwarts
    Jul 2, 2009
  4. A
    Replies:
    7
    Views:
    658
  5. , India

    pointer to an array vs pointer to pointer

    , India, Sep 20, 2011, in forum: C Programming
    Replies:
    5
    Views:
    502
    James Kuyper
    Sep 23, 2011
Loading...

Share This Page