Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-24 16:25:48


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, January 24, 2002 3:41 PM
Subject: Re: [boost] function/bind with extern "C"?

> From: "David Abrahams" <david.abrahams_at_[hidden]>
> > Beg pardon, but do function and bind work with extern "C" functions?
> > That would be extremely useful to me.
>
> #include <boost/bind.hpp>
>
> extern "C" void f(void) {}
>
> int main()
> {
> boost::bind(f)();
> }
>
> works for me on MSVC, bcc, g++. I don't know why. :-) Perhaps because an
> extern "C" function pointer happens to be the same as an ordinary C++
> function pointer on win32.

Yes, I expected that. It's not the same everywhere.
G++ 3.0.3 likes it, but 2.95.x chokes on windows and on linux:

Here are the errors from g++ on linux:

cd /root/boost/libs/python/test/
jam -sBOOST_ROOT=/root/boost -sTOOLS=gcc
Jamrules: No such file or directory
...found 37 targets...
...updating 2 targets...
gcc-C++-action bin/foo/gcc/debug/runtime-link-dynamic/foo.o
/root/boost/boost/bind.hpp: In instantiation of
`boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>':
/root/boost/boost/bind/bind_template.hpp:16: instantiated from
`boost::_bi::bind_t<boost::_bi::unspecified,int (*)(...),boost::_bi::list0>'
foo.cpp:15: instantiated from here
/root/boost/boost/bind.hpp:53: `int (*)(...)' is not a class, struct, or
union type
/root/boost/boost/bind/bind_template.hpp: In instantiation of
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>':
foo.cpp:15: instantiated from here
/root/boost/boost/bind/bind_template.hpp:16: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:19: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:19:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()(...)' must be a nonstatic member
function
/root/boost/boost/bind/bind_template.hpp:25: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:25:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()(...)' must be a nonstatic member
function
/root/boost/boost/bind/bind_template.hpp:25:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()(...)' has already been declared in
`boost::_bi::bind_t<boost::_bi::unspecified,int (*)(...),boost::_bi::list0>'
/root/boost/boost/bind/bind_template.hpp:31: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:31:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1>(...)' must be a nonstatic
member function
/root/boost/boost/bind/bind_template.hpp:37: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:37:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1>(...)' must be a nonstatic
member function
/root/boost/boost/bind/bind_template.hpp:37: `template <class A1> {error}'
has already been declared in `boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>'
/root/boost/boost/bind/bind_template.hpp:43: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:43:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1, A2>(...)' must be a nonstatic
member function
/root/boost/boost/bind/bind_template.hpp:49: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:49:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1, A2>(...)' must be a nonstatic
member function
/root/boost/boost/bind/bind_template.hpp:49: `template <class A1, class A2>
{error}' has already been declared in
`boost::_bi::bind_t<boost::_bi::unspecified,int (*)(...),boost::_bi::list0>'
/root/boost/boost/bind/bind_template.hpp:55: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:55:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1, A2, A3>(...)' must be a
nonstatic member function
/root/boost/boost/bind/bind_template.hpp:61: no type named `type' in `struct
boost::_bi::result_traits<boost::_bi::unspecified,int (*)(...)>'
/root/boost/boost/bind/bind_template.hpp:61:
`boost::_bi::bind_t<boost::_bi::unspecified,int
(*)(...),boost::_bi::list0>::operator ()<A1, A2, A3>(...)' must be a
nonstatic member function

<snip>

/root/boost/boost/bind.hpp:884: confused by earlier errors, bailing out

g++ -c -Wall -ftemplate-depth-100 -g -O0 -fno-inline -I"." -I"/root/boo
st" -o "bin/foo/gcc/debug/runtime-link-dynamic/foo.o" "foo.cpp"

...failed gcc-C++-action bin/foo/gcc/debug/runtime-link-dynamic/foo.o ...
...removing bin/foo/gcc/debug/runtime-link-dynamic/foo.o
...skipped <foo/gcc/debug/runtime-link-dynamic>foo for lack of
<foo/gcc/debug/runtime-link-dynamic>foo.o...
...failed updating 1 target...
...skipped 1 target...

Compilation exited abnormally with code 1 at Thu Jan 24 16:16:50


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk