Fortran Gains New Intrinsic: c_f_strpointer for String Pointers
Adds the `c_f_strpointer` intrinsic to Fortran, enabling interoperability with C string pointers as part of Fortran 2023 support.
The c_f_strpointer intrinsic has been added to Fortran, implementing a missing feature from the Fortran 2023 standard. This intrinsic allows Fortran programs to interoperate with C code that uses string pointers, by providing a way to associate a Fortran character variable with the target of a C string pointer. This enhancement expands Fortran’s ability to work with C libraries.
In Details
This commit introduces c_f_strpointer to the Fortran front end, specifically in check.cc, intrinsic.cc, and trans-intrinsic.cc. It involves adding a new gfc_check_c_f_strpointer function for semantic analysis, a new GFC_ISYM_C_F_STRPOINTER symbol, and a conv_isocbinding_subroutine_strpointer function for code generation. The changes also include modifications to iso-c-binding.def and updates to the documentation in intrinsic.texi.
For Context
This commit introduces a new feature to Fortran that improves its ability to work with C code. Modern Fortran has an "ISO C Binding" feature that allows Fortran code to directly call functions written in C, and vice versa. The new c_f_strpointer intrinsic makes it easier for Fortran programs to manipulate character strings that are managed by C code, which is important when interfacing with external C libraries. This brings Fortran closer to full compliance with the Fortran 2023 standard.