C / C ++ Opaque Pointer Library

Is there already a written library / header for managing C ++ objects from C using opaque pointers / descriptors?

I can write one myself, but I would prefer to use a solution already made, especially if it has fortran bindings.

my specific requirements:

  • shell builder (my idea is to use the boost preprocessor)
  • processing objects using integer (rather than raw pointers) descriptors (Γ  la mpi) to provide verification and special values ​​and some portability with 64-bit fortran.

thank

+3
source share
2 answers

++

Foo foo; // C++ object we want to access

Foo &foo_factory(); // C++ function we want to call

extern "C" void * get_foo() // extern "C" so C can call function
    { return (void *) & foo; } // cast it to an opaque void * so C can use it

extern "C" void * create_foo()
    { return (void *) & foo_factory(); }

C

extern void * get_foo();
extern void * create_foo();

void* , .

Fortran extern "C" ( C ) ++ extern "Fortran". . .

, . , , , .

+4

, C, Fortran, , ISO C, Fortran, C. , ISO C Fortran C , , . , (untested) Fortran:

module my_fortran_binding

use iso_c_binding

implicit none

interface get_foo_interf

   function get_foo () bind (C, name="get_foo")

      import

      type (C_PTR) :: get_foo

   end function get_foo

end interface get_foo_interf


interface create_foo_interf
  etc....
end create_foo_interf

end module my_fortran_binding
0

Source: https://habr.com/ru/post/1742693/


All Articles