Function pointers and inline definitions

Discussion in 'C Programming' started by raphfrk@gmail.com, Dec 9, 2009.

  1. Guest

    This is probably not possible, but I thought I would ask.

    Assuming that there is a function that takes a pointer to a function
    as an input. Can the passed function be defined inline.

    For example:

    void func_func( void (*func_tst)( int ) , int a )
    {

    (*func_tst)( a );

    }

    int main( int argc, char **argv )
    {

    func_func(
    (void (*) (int a))
    {
    printf( "%n" , a );
    },
    7
    );

    }

    The effect would be that func_func would call the inlined function and
    pass it 7.
     
    , Dec 9, 2009
    #1
    1. Advertising

  2. "" <> writes:

    > This is probably not possible, but I thought I would ask.
    >
    > Assuming that there is a function that takes a pointer to a function
    > as an input. Can the passed function be defined inline.


    When I read this, I though "yes" because a "function defined inline"
    might mean a function whose definition includes the qualifier "inline"
    and that is possible. However...

    > For example:
    >
    > void func_func( void (*func_tst)( int ) , int a )
    > {
    >
    > (*func_tst)( a );
    >
    > }
    >
    > int main( int argc, char **argv )
    > {
    >
    > func_func(
    > (void (*) (int a))
    > {
    > printf( "%n" , a );
    > },
    > 7
    > );
    >
    > }
    >
    > The effect would be that func_func would call the inlined function and
    > pass it 7.


    No, not possible. I'd call this a "function literal" rather than an
    inlined function but, whatever you call it, you can't do it in
    standard C.

    --
    Ben.
     
    Ben Bacarisse, Dec 9, 2009
    #2
    1. Advertising

  3. Guest

    On Dec 9, 2:29 pm, Ben Bacarisse <> wrote:
    > No, not possible. I'd call this a "function literal" rather than an
    > inlined function but, whatever you call it, you can't do it in
    > standard C.


    Bah :). Thanks for the info.
     
    , Dec 9, 2009
    #3
    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. Nish
    Replies:
    4
    Views:
    496
    Thomas Stegen
    Oct 8, 2004
  2. TGOS
    Replies:
    3
    Views:
    381
    Kevin Bracey
    Feb 28, 2005
  3. Ajay
    Replies:
    5
    Views:
    395
    Pete Becker
    Apr 1, 2006
  4. Replies:
    7
    Views:
    447
  5. Hicham Mouline

    in-class function definitions, inline

    Hicham Mouline, Jan 31, 2008, in forum: C++
    Replies:
    1
    Views:
    294
    Alf P. Steinbach
    Jan 31, 2008
Loading...

Share This Page