Make sure iso_c_binding is available at compile time

In the context of a mixed C / Fortran application, is there a way to verify that the compiler knows "iso_c_binding" (for example, GCC 4.1.2 does not know this, while 4.3.4 does), like pre-processing processes or something else? I cannot afford to simply check the version of GCC, since I can use other compilers.

thank

+5
source share
2 answers

Your two options that I can think of are to translate your own version iso_c_bindingfor systems that do not have this module ( as suggested by @HighPerformanceMark ) or use preprocessors to conditionally compile parts of your code depending on the version of the compiler. In both cases, you will have to work for your code to be portable across systems. As suggested by @HighPerformanceMark, you can copy and paste the iso_c_bindingopen source implementation, but for each new system you transfer your code, you will need to check the correctness of this implementation.

, , , iso_c_binding , . , " GCC, ". , , , , .

, . gfortran:

GNU Fortran , __GFORTRAN__ __GNUC__, __GNUC_MINOR__ __GNUC_PATCHLEVEL__ .

, precomp.inc, , , . , , iso_c_binding, HAS_ISO_C_BINDING ( ). precomp.inc . :

!> \file precomp.inc
!! Preprocessor feature detection.

#if defined(__GFORTRAN__)

#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
#define HAS_ISO_C_BINDING 1
#else
#define HAS_ISO_C_BINDING 0
#endif

#elif defined(__INTEL_COMPILER)
#error "I haven't implemented this yet..."

#else
#error "Compiler not yet supported."

#endif

#else HAS_ISO_C_BINDING=0, iso_c_binding.

Fortran :

program main

#include 'precomp.h'
#if HAS_ISO_C_BINDING
use iso_c_binding
#endif

implicit none

! Some code...

#if HAS_ISO_C_BINDING
! Code which depends on iso_c_binding
#else
! Fallback code
#end if

! Some more code...

end program main

, , , iso_c_binding . , @HighPerformanceMark, , . , iso_c_binding , , , .

+2

. , Fortran ( , ) C, C. C, .

, , F2003 ISO_C_BINDING, , C ( , C_FLOAT, C_REAL .., , " " ").

, C ( , F2003, C_INT, C_LOC, C_F_POINTER ..), :

  • Fortran, USE ( , Fortran ). , , , , , .

  • Fortran.

0

All Articles