This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ISO C binding and character variables


I was wondering if somone could tell me how the ISO C binding is
supposed to work for Fortran character variables.  Attached is a test
case that is cut down from gfortran.dg/c_kind_params.f90.

It fails on IA64 HP-UX because this platform has a different parameter
passing mechanism for 'char x' and for 'char x[]'.  A simple char
variable is passed in a register and padded on the left.  Aggregrate
types (arrays or structures) are passed in registers and padded on the
right.  What is the 'right' way to handle the argument in this test
case?  C seems to be handling it as a simple variable and Fortran seems
to be handling it as an aggregate (array).  Should the C code be
rewritten to make my_char an array?  Or is the Fortran translation to
the C type wrong?

Steve Ellcey
sje@cup.hp.com

-------- C portion of test ---------

nclude <stdint.h>

void param_test(char my_char);


int main(int argc, char **argv)
{
   char my_char = 'y';
   param_test(my_char);
   return 0;
}/* end main() */

--------- Fortran portion of test ------

module c_kind_params
  use, intrinsic :: iso_c_binding
  implicit none

contains
  subroutine param_test(my_char) bind(c)
    character(c_char), value :: my_char
    if(my_char /= c_char_'y') call abort()
  end subroutine param_test

end module c_kind_params


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]