Question Details

No question body available.

Tags

c fortran

Answers (3)

March 27, 2026 Score: 1 Rep: 40,671 Quality: Medium Completeness: 80%

You should provide Minimal Complete Verifiable Example, so your intent is clear and it is easier to provide a nice answer.

Anyway here I proposal of my own MCVE where it just works:

Fortran side code:

module mymodule
  use isocbinding
  implicit none

type, bind(c) :: coordinatesfloat real(c
float) :: x real(cfloat) :: y end type coordinatesfloat

contains

subroutine process
coords(coords) bind(c, name="processcoords") type(coordinatesfloat), intent(inout) :: coords coords%x = coords%x * 2.0 coords%y = coords%y * 2.0 end subroutine

end module my
module

C++ side code:

#include 

// Matches the Fortran bind(c) type exactly struct coordinatesfloat { float x; float y; };

// Declare the Fortran function with C linkage extern "C" { void process_coords(coordinatesfloat* coords); }

int main() { coordinatesfloat c = {3.0f, 4.0f}; std::cout
March 27, 2026 Score: 0 Rep: 18,163 Quality: Low Completeness: 0%

It looks fine, although OP wants to use it in C.

March 27, 2026 Score: 0 Rep: 40,671 Quality: Low Completeness: 20%

Here C++ is used just to print some data. Everything else is C or Fortran. https://godbolt.org/z/qxTjMG8Gh