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

Should stdlib have interfaces to C functions? #583

Open
Beliavsky opened this issue Nov 28, 2021 · 2 comments
Open

Should stdlib have interfaces to C functions? #583

Beliavsky opened this issue Nov 28, 2021 · 2 comments

Comments

@Beliavsky
Copy link

The FizzBuzz discussion at Discourse, especially the code by Steve Kargl that calls C printf and puts, suggests to me that some C functions, especially those doing I/O, should have Fortran interfaces so that a Fortran programmer does not need to drop down to C to write performant code. Which C functions if any should have interfaces in stdlib? Such functions would also have Fortran drivers demonstrating their use.

@ivan-pi
Copy link
Member

ivan-pi commented Nov 28, 2021

I would be in favor of this as indicated in #1 (comment) and a few comments further:

I've gone ahead and prepared interfaces for a few elements of the C standard library in https://github.com/ivan-pi/fortran-libc (malloc, calloc, realloc, free, qsort, and the entire <time.h>)
I think it would be nice to have this as an optional component to stdlib. That way not everyone has to go through the trouble of writing these interfaces next time they need to allocate some C memory from Fortran. (Alternatively an automatic interface generator like swig-fortran could be used.)

However there are few questions which arise with the C interface:

  • Should procedures have the prefix c_?
  • Should the procedures remain true to their original C versions, or use some level of Fortran wrapping (e.g. wrapping string procedures so the c_new_line is added internally)?
  • Should the procedures be generated automatically using a tool (SWIG, Shroud, and a few others exist) or crafted manually?
  • Should C macro constants be wrapped as functions or compile-time constants?
  • Should structs be wrapped as opaque objects (I believe this is needed in some cases, because the platform-specific implementations of C stdlib might provide a few extra things to what is specified in ISO C standard)?
  • Should procedures with a Fortran equivalent remain out (e.g. using C math functions should be discouraged)?

A few other related issues and repositories:

There are also several Discourse threads with bits & pieces of C standard library procedures.

@gareth-nx
Copy link
Contributor

Also somewhat related: #573 (the test code compares with existing hash functions written in C and C++, and we will discuss how to best manage this).

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

No branches or pull requests

3 participants