Skip to content

Conversation

@MakisH
Copy link
Member

@MakisH MakisH commented Mar 19, 2024

Closes #1, implementing (to the extent I understand) the suggestions of @ivan-pi.

I also tried to make the length an optional argument, to maintain compatibility with user code. I am also trying to avoid touching the preCICE C/Fortran bindings for now, as we just had a breaking release.

Currently, building the (unmodified) solverdummy.f90 leads to the following error:

fortran-module/examples/solverdummy [nullterminated]$ make
gfortran -g solverdummy.f90 -o solverdummy -I../.. -L/home/gc/repos/precice/precice/build -lprecice
/usr/bin/ld: /tmp/ccQ2PSRq.o: in function `MAIN__':
/home/gc/repos/precice/fortran-module/examples/solverdummy/solverdummy.f90:38: undefined reference to `__precice_MOD_precicef_create'

Any clue what I am doing wrong?

@MakisH MakisH self-assigned this Mar 19, 2024
@MakisH
Copy link
Member Author

MakisH commented Nov 11, 2025

Together with @ivan-pi, we took now a different approach:

Instead of differentiating between null- and non-null-terminated strings in the C interface, we just adopt the de facto Fortran calling convention, as already done in the core library.

We dropped the bind(c) attribute. The way we now write it, automatically appends a trailing _ in each function name in the binary.

We also removed the dimension arguments present in the bind(c) version, and replaced them with len=* arguments. This enables the hidden length argument added by the compiler.

Important here would be that this would need special handling on Windows Fortran compilers, which adopt a different convention. We would need to specify FortranCInterface in the core library CMakeLists.txt, to automatically detect the right convention (add an underscore or not). This would assume the presence of a Fortran compiler.

We modified the precicef_create and improved the style of the example, I will adapt the rest of the files and ask for a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing strings requires passing their lengths as well

3 participants