Le 08/06/2015 17:31, Jan Hubicka a écrit :
> Hi,
> to furhter add to the topics to discuss, I noticed that Fortran FE seems to
> be quite
> ambivalent about C_CHAR type:
> [jh@gcc2-power8 gcc]$ cat ../b.f90
> ! This testcase will abort if C_CHAR types are not interoperable
> module lto_type_merge_test
> use, intrinsic :: iso_c_binding
> implicit none
>
> contains
> function types_test1(V) bind(c)
> USE, INTRINSIC :: ISO_C_BINDING
> CHARACTER(C_CHAR) :: types_test1
> CHARACTER(C_CHAR), VALUE :: V
> types_test1 = V
> end function types_test1
> end module lto_type_merge_test
>
> [jh@gcc2-power8 gcc]$ cat ../a.c
> extern unsigned char types_test1 (char v);
> void
> main ()
> {
> if (types_test1 ('a') != 'a')
> __builtin_abort ();
> return 0;
> }
>
> As my fortran-fu goes, i think this testcase is correct. Fortran FE however
> builds types_test1 as a function return char but taking the array of size of 1
> as a parameter.
C_CHAR is a named constant of value 1 (the number of bytes of a char),
and character(foo) declares a string of length foo and default kind
(which is 1 for character types).
So it is expected that the argument is an array.
If you want to declare a single character, you have to use an integer of
kind 1.
types_test1's result and v should have type integer(c_char), I think.
Mikael