what is proper syntax for: extern "C" { friend void xfunc(); }

Discussion in 'C++' started by Shea Martin, Nov 18, 2003.

  1. Shea Martin

    Shea Martin Guest

    I am trying to use a system call which takes a function ptr. My
    compiler won't compile the code if I give the system_call a ptr to a
    class member function, A::func(). To combat this, I created an
    function, xfunc(A a), which wraps A::func(). For this to work properly,
    I need to make xfunc() a friend of class A.

    I am getting compile warnings regarding the system call being passed a
    function ptr, when it is expecting an extern "C" function ptr. If
    comment out code in xfunc() which requires it to be a friend of A, and
    wrap xfunc() in extern "C" {xfun();}, then everything compiles nicely.

    So now how do I get my cake and eat it too. As in, how do I define an
    extern "C" function to be a friend of A?

    I tried this:
    class A
    {
    extern "C" { friend void xfunc(); }
    };

    but it does not compile. Anyone know the correct syntax, or is this
    possible?

    Thanks,

    ~S
     
    Shea Martin, Nov 18, 2003
    #1
    1. Advertising

  2. Shea Martin

    Shea Martin Guest

    Re: what is proper syntax for: extern "C" { friend void xfunc();}

    Shea Martin wrote:
    > I am trying to use a system call which takes a function ptr. My
    > compiler won't compile the code if I give the system_call a ptr to a
    > class member function, A::func(). To combat this, I created an
    > function, xfunc(A a), which wraps A::func(). For this to work properly,
    > I need to make xfunc() a friend of class A.
    >
    > I am getting compile warnings regarding the system call being passed a
    > function ptr, when it is expecting an extern "C" function ptr. If
    > comment out code in xfunc() which requires it to be a friend of A, and
    > wrap xfunc() in extern "C" {xfun();}, then everything compiles nicely.
    >
    > So now how do I get my cake and eat it too. As in, how do I define an
    > extern "C" function to be a friend of A?
    >
    > I tried this:
    > class A
    > {
    > extern "C" { friend void xfunc(); }
    > };
    >
    > but it does not compile. Anyone know the correct syntax, or is this
    > possible?
    >
    > Thanks,
    >
    > ~S
    >



    I just tried this:

    extern "C" { void xfunc(); }
    class A
    {
    friend xfunc;
    };

    and it compiled, without warning or error. Anyone see anything wrong
    with this?

    ~S
     
    Shea Martin, Nov 18, 2003
    #2
    1. Advertising

  3. Re: what is proper syntax for: extern "C" { friend void xfunc();}

    Shea Martin wrote:
    > I am trying to use a system call which takes a function ptr. My
    > compiler won't compile the code if I give the system_call a ptr to a
    > class member function, A::func(). To combat this, I created an
    > function, xfunc(A a), which wraps A::func(). For this to work properly,
    > I need to make xfunc() a friend of class A.
    >
    > I am getting compile warnings regarding the system call being passed a
    > function ptr, when it is expecting an extern "C" function ptr. If
    > comment out code in xfunc() which requires it to be a friend of A, and
    > wrap xfunc() in extern "C" {xfun();}, then everything compiles nicely.
    >
    > So now how do I get my cake and eat it too. As in, how do I define an
    > extern "C" function to be a friend of A?
    >
    > I tried this:
    > class A
    > {
    > extern "C" { friend void xfunc(); }
    > };
    >
    > but it does not compile. Anyone know the correct syntax, or is this
    > possible?




    extern "C" { void xfunc(); }

    class A
    {
    friend void xfunc();
    };
     
    Gianni Mariani, Nov 18, 2003
    #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. Bill Zhao
    Replies:
    2
    Views:
    391
    David Hilsee
    Aug 12, 2004
  2. Ollej Reemt
    Replies:
    7
    Views:
    606
    Jack Klein
    Apr 22, 2005
  3. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    843
    The Real OS/2 Guy
    Oct 28, 2003
  4. Replies:
    5
    Views:
    886
    S.Tobias
    Jul 22, 2005
  5. Replies:
    1
    Views:
    439
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page