function-pointers

JNI for C using Swig & trouble with function pointer callback

放肆的年华 提交于 2020-01-04 01:49:21
问题 we have a C function in one of the libraries which are loaded in java, which accepts a function pointer function defination as below typedef char int8 typedef unsigned short uint16 uint32 poll_broadcasts(void *(pfn)(int8*,uint16)); In C it is used as below void handle_broadcasts( int8 *broadcast, uint16 length ) uint32 a = poll_broadcasts( (void*(*)(int8*,uint16)) handle_broadcasts ) But when you use Swig to generate JNI wrapper it creates following definition for poll_broadcast public static

How to static cast throwing function pointer to noexcept in C++17?

杀马特。学长 韩版系。学妹 提交于 2020-01-03 06:59:07
问题 C++17 makes noexcept part of a function's type. It also allows implicit conversions from noexcept function pointers to potentially throwing function pointers. void (*ptr_to_noexcept)() noexcept = nullptr; void (*ptr_to_throwing)() = ptr_to_noexcept; // implicit conversion http://eel.is/c++draft/expr.static.cast#7 says that static_cast can perform the inverse of such a conversion. void (*noexcept_again)() noexcept = static_cast<void(*)() noexcept>(ptr_to_throwing); Unfortunately, both GCC and

function pointer incompatible pointer types void (*)(void *) from void (my_type *)

一个人想着一个人 提交于 2020-01-03 05:46:04
问题 I'm having getting the above warning and understand it, but just don't know how to fix it. My code is below, but basically what I'm doing is storing a function pointer in a struct, and initializing the struct in another function that I call from my main. The code seems to compile when I use it with a default function (i.e. free()) but not when I use it with the test_func function below. Thoughts? Struct: typedef struct my_struct { my_type **double_pointed; int num; void (*funcp)(void *data);

Boost.Python function pointers as class constructor argument

≡放荡痞女 提交于 2020-01-02 21:58:16
问题 I have a C++ class that requires a function pointer in it's constructor ( float(*myfunction)(vector<float>*) ) I've already exposed some function pointers to Python. The ideal way to use this class is something like this: import mymodule mymodule.some_class(mymodule.some_function) So I tell Boost about this class like so: class_<SomeClass>("some_class", init<float(*)(vector<float>*)>); But I get: error: no matching function for call to 'register_shared_ptr1(Sample (*)(std::vector<double, std:

Boost.Python function pointers as class constructor argument

こ雲淡風輕ζ 提交于 2020-01-02 21:58:00
问题 I have a C++ class that requires a function pointer in it's constructor ( float(*myfunction)(vector<float>*) ) I've already exposed some function pointers to Python. The ideal way to use this class is something like this: import mymodule mymodule.some_class(mymodule.some_function) So I tell Boost about this class like so: class_<SomeClass>("some_class", init<float(*)(vector<float>*)>); But I get: error: no matching function for call to 'register_shared_ptr1(Sample (*)(std::vector<double, std:

What is the difference between pointer to array and pointer to pointer?

℡╲_俬逩灬. 提交于 2020-01-02 14:31:53
问题 I'm new in programming and learning about pointers in array. I'm a bit confused right now. Have a look at the program below: #include <stdio.h> int fun(); int main() { int num[3][3]={23,32,478,55,0,56,25,13, 80}; printf("%d\n",*(*(num+0)+1)); fun(num); printf("%d\n", *(*(num+0)+1)); *(*(num+0)+0)=23; printf("%d\n",*(*(num+0))); return 0; } int fun(*p) // Compilation error { *(p+0)=0; return 0; } This was the program written in my teacher's notes. Here in the main() function, in the printf()

What is the difference between pointer to array and pointer to pointer?

一个人想着一个人 提交于 2020-01-02 14:30:11
问题 I'm new in programming and learning about pointers in array. I'm a bit confused right now. Have a look at the program below: #include <stdio.h> int fun(); int main() { int num[3][3]={23,32,478,55,0,56,25,13, 80}; printf("%d\n",*(*(num+0)+1)); fun(num); printf("%d\n", *(*(num+0)+1)); *(*(num+0)+0)=23; printf("%d\n",*(*(num+0))); return 0; } int fun(*p) // Compilation error { *(p+0)=0; return 0; } This was the program written in my teacher's notes. Here in the main() function, in the printf()

Cython: How to expose void* and function pointer in struct?

六眼飞鱼酱① 提交于 2020-01-02 13:28:06
问题 I have a C header with: typedef struct { <normal members> void (*cb_func)(glp_tree *T, void *info); void *cb_info; <normal members> } glp_iocp; Currently, in my pxd file: ctypedef struct IntOptCP "glp_iocp": <normal members> int out_dly # mip.out_dly (milliseconds) #void (*cb_func)(Tree* tree, void* info) # mip.cb_func #void* cb_info # mip.cb_info <normal members> In a pyx file, at some point, I do (essentially): cdef class MyClass: IntOptCP _iocp <__cintit__ and the like> def some_method

Cython: How to expose void* and function pointer in struct?

谁说胖子不能爱 提交于 2020-01-02 13:27:05
问题 I have a C header with: typedef struct { <normal members> void (*cb_func)(glp_tree *T, void *info); void *cb_info; <normal members> } glp_iocp; Currently, in my pxd file: ctypedef struct IntOptCP "glp_iocp": <normal members> int out_dly # mip.out_dly (milliseconds) #void (*cb_func)(Tree* tree, void* info) # mip.cb_func #void* cb_info # mip.cb_info <normal members> In a pyx file, at some point, I do (essentially): cdef class MyClass: IntOptCP _iocp <__cintit__ and the like> def some_method

Non-type template function pointer to const member function

僤鯓⒐⒋嵵緔 提交于 2020-01-02 05:42:04
问题 I'm writing a delegate class but it fails to take const member functions. Here is a test case : class foo { public: void MemberFunction() { printf("non const member function\n"); } void ConstMemberFunction() const { printf("const member function\n"); } }; template <class C, void (C::*Function)()> void Call(C* instance) { (instance->*Function)(); } int main (int argc, char** argv) { foo bar; Call<foo,&foo::MemberFunction>(&bar); Call<foo,&foo::ConstMemberFunction>(&bar); } Now the compiler