An adaptor for C++ callbacks with C and Fortran librariesAn adaptor for C++ callbacks with C and Fortran libraries
Faculty of Sciences. Mathematics and Computer Science
Modeling Of Systems and Internet Communication (MOSAIC)
Computer physics communications. - Amsterdam
184(2013):3, p. 824-832
University of Antwerp
Object-oriented programming using C++ is increasingly being adopted in the development of scientific codes. A recurrent issue in this regard is the interaction of newly developed codes with existing legacy libraries written in C or Fortran. Often, one needs to pass raw function pointers to such libraries procedures for callback purposes. This is problematic as it conflicts with one of the cornerstones of object-oriented programming: the association of functions and data through objects. Currently ad hoc approaches are used to deal with this issue, but these are error-prone and lack reusability. We present a generic adaptor that is able to wrap any callable C++ entity and provide a raw function pointer that is compatible with C or Fortran library routines. This allows for an object-oriented style of programming, while interfacing with legacy libraries in a straightforward manner.