Skip to content

Files

Latest commit

Feb 3, 2018
db8d977 · Feb 3, 2018

History

History
85 lines (58 loc) · 3.14 KB

c++_calls_c.md

File metadata and controls

85 lines (58 loc) · 3.14 KB

C++_CALLS_C
C++ Main Program Calls C Functions {#c_calls_c-c-main-program-calls-c-functions align="center"}


C++_CALLS_C is a directory of C++ programs which illustrates how a C++ program can call a C function.

For this example, the KRONROD package is used. Note that the KRONROD library is available in C++ and in C, so this example is not created out of necessity (the C++ main program could have simply called the C++ version of KRONROD). Instead, it is intended as an example of how to do this when you have to (you don't have a C++ version of the routines you want to use.)

When calling a C function from a C++ function, there are some simple things that may be enough to guarantee success.

  • the C++ code should declare interfaces to the C functions using the "extern C" qualifier, as in

    extern "C" 
    {
      void kronrod ( int n, double eps, double x[], double w1[], double w2[] );
      void timestamp ( );
    }
    

Licensing: {#licensing align="center"}

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages: {#languages align="center"}

C++_CALLS_C is available in a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs: {#related-data-and-programs align="center"}

C++_CALLS_F77, C++ programs which call a FORTRAN77 subroutine.

C++_CALLS_F90, C++ programs which call a FORTRAN90 subroutine.

KRONROD, a C library which can compute a Gauss and Gauss-Kronrod pair of quadrature rules of arbitrary order, by Robert Piessens, Maria Branders.

KRONROD, a C++ library which can compute a Gauss and Gauss-Kronrod pair of quadrature rules of arbitrary order, by Robert Piessens, Maria Branders.

MIXED, C++ programs which call a function written in another programming language.

Source Code: {#source-code align="center"}

KRONROD is the C source code for the KRONROD library. It should be essentially unchanged from the standard version.

KRONROD_PRB is the C++ source code for the main program. Some changes have been made from the standard version in order to adjust for the fact that we are calling a FORTRAN77 subroutine.

Examples and Tests: {#examples-and-tests align="center"}

You can go up one level to the C++ source codes.


Last revised on 18 March 2014.