Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API with and without null-terminated strings #26

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

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 and others added 2 commits March 19, 2024 15:47
@@ -312,4 +314,21 @@ end subroutine precicef_get_version_information

end interface

contains
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still want that users call precicef_create, so they should be outside the contains block. However, it looks like I cannot call subroutines from inside an interface. What would be the right way here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you have it now as a module procedure (a thin wrapper of the preCICE C API). Isn't that what you want?

Copy link
Member Author

@MakisH MakisH Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want that users call the precicef_create variant without having to provide neither null-terminated strings, nor placeholder lengths. For this, I would need the precicef_create to not be internal (inside the contains), no?

If I ask the users to call the precicec_create, then they need to provide null-terminated strings.

Should I maybe split it into two different modules? Not sure if I can modify the arguments in an interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Fortran parlance, interface blocks are like function declarations in C. They are specification statements (i.e. non-executable).

When you want to define a procedure, it must be in the "contains" part:

module precice
 ! ... specification ...
contains
 ! ... procedure definitions (including executable statements) ...
end module

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that helps! But then, I understand that both what I have in the interface and in the contains need to have the same name.

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
2 participants