By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,165 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,165 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 22 '05 #2

P: n/a
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();
};

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.