This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/51434] ICE with scalar init of an array parameter, used in DT default init with transfer
- From: "sgk at troutmask dot apl.washington.edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 06 Dec 2011 15:59:17 +0000
- Subject: [Bug fortran/51434] ICE with scalar init of an array parameter, used in DT default init with transfer
- Auto-submitted: auto-generated
- References: <bug-51434-4@http.gcc.gnu.org/bugzilla/>
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.