GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran Performance Win

Fortran's f_c_string Intrinsic Gets Performance and Docs Boost

Improves efficiency of the `f_c_string` intrinsic in Fortran, adds constant string folding, and provides documentation.

The f_c_string intrinsic in Fortran was reimplemented for better efficiency. The old implementation performed multiple allocations and copies; the new version folds constant string arguments and uses a single allocation and copy for other cases. This reduces overhead when interoperating with C code. The commit also adds missing documentation for the intrinsic to the gfortran manual.

In Details

This commit rewrites conv_isocbinding_function in trans-intrinsic.cc to improve the implementation of the F_C_STRING intrinsic. The previous implementation was inefficient due to multiple allocations. The new version folds constant string arguments at compile time. Documentation for F_C_STRING is added to intrinsic.texi.

For Context

This commit enhances Fortran's ability to interoperate with C code via the f_c_string intrinsic. Fortran's ISO C Binding allows Fortran programs to call C functions and vice versa. The f_c_string intrinsic converts a Fortran string to a C string. The improved implementation reduces memory allocations and copies, leading to faster execution. Documentation is added to explain how to use this feature.

Filed Under: fortraninteroperabilityoptimizationdocumentation