Skip to content
/ funcptr Public

A bridge for convert c++ function object to c function pointer (with user pointer)

License

Notifications You must be signed in to change notification settings

codehz/funcptr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FuncPtr

A bridge for convert c++ function object to c function pointer (with user pointer)

Have you ever lost your head in passing a function to the C interface? Are you still fighting against void * ? With funcptr, you no longer have to worry about passing C++ functions in the C interface

Usage

  void some_c_interface(int arg, void(*callback)(int input, void *user), void *user);

  using namespace func_ptr;
  int captured;
  funcptr lambda{[&](int input /* Normal parameter */, user_pointer /* Use this for user pointer placeholder */) { process(input, captured); }};
  some_c_interface(arg /* Normal parameter */, lambda, lambda.holder() /* User pointer */);

It support

  1. Pass normal function to c interface (Not recommanded, please pass it directly)
  2. Pass std::function to c interface
  3. Pass lambda and std::bind

Lifetime

All funcptr

TODO

  1. Add a asm magic for pass c++ function to c interface that no user pointer.

LICENSE

Unlicensed see LICENSE;

About

A bridge for convert c++ function object to c function pointer (with user pointer)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published