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

S

Shea Martin

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
 
S

Shea Martin

Shea said:
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
 
G

Gianni Mariani

Shea said:
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();
};
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top