[Bug fortran/51434] ICE with scalar init of an array parameter, used in DT default init with transfer
sgk at troutmask dot apl.washington.edu
gcc-bugzilla@gcc.gnu.org
Tue Dec 6 16:00:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51434
--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-12-06 15:59:17 UTC ---
On Tue, Dec 06, 2011 at 06:40:07AM +0000, andy.nelson at lanl dot gov wrote:
>
> Can you recommend a better way to solve this problem, besides redefining the C
> standard to accept 'scalar' character strings longer than one character?
>
Don't know if the code conforms to the C and Fortran standards,
but this appears to work.
% cat foo.c
#include <stdio.h>
void
foo(char *s)
{
printf("%s\n", s);
}
% cat bar.f90
program bar
use iso_c_binding
character(len=5,kind=c_char) :: s
interface
subroutine foo(s) bind(c)
use iso_c_binding
character(len=1, kind=c_char) :: s
end subroutine foo
end interface
s = 'abcd'
call foo(s // char(0))
end program bar
% gcc46 -c foo.c
% gfortran46 -o z bar.f90 foo.c
% ./z
abcd
It should be straight forward to modify your code. The
key is to null terminate the string you are passing into
the C routine, i.e., the char(0) above.
More information about the Gcc-bugs
mailing list