GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fix CHARACTER(c_char),VALUE dummy of BIND(C) interface

Fortran compiler now correctly passes scalar CHARACTER(c_char) dummies with VALUE attribute by value.

This commit fixes an issue in the Fortran compiler (gfortran) where scalar CHARACTER(c_char) dummy arguments with the VALUE attribute were not always passed by value as required by the BIND(C) interface. The fix ensures that for such dummy arguments, only the first character is passed by value, which is the correct behavior for C interoperability. A new test case has been added to verify this correction.

In Details

The trans-expr.cc module's conv_scalar_char_value function is modified to correctly handle Fortran CHARACTER(c_char) dummy arguments with the VALUE attribute when interfacing with C. Previously, non-constant strings could lead to incorrect passing mechanisms. The corrected logic now ensures that for these specific dummy arguments, only the first character is passed by value, aligning with C's single-byte character passing convention and Fortran's VALUE attribute semantics for C interoperability.

For Context
BIND(C)
A Fortran language feature that allows procedures to interoperate with C functions. It specifies how Fortran data types and procedure interfaces map to their C counterparts.
dummy argument
In Fortran, a parameter in a procedure's interface that receives a value from the calling procedure. It acts like a local variable within the called procedure.
VALUE attribute
A Fortran attribute that, when applied to a dummy argument, specifies that the argument should be passed by value rather than by reference (the default for most types).
c_char
A Fortran intrinsic type that corresponds to a single character, often used in conjunction with BIND(C) for C interoperability. It typically maps to a C char.
gfortran
The Fortran compiler included in the GCC suite.
Filed Under: fortranbind(c)interoperabilitybugfix