http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51434
--- Comment #7 from Andy Nelson <andy.nelson at lanl dot gov> 2011-12-06 22:25:00 UTC --- Seems it doesn't work in general. My attempt at getting it to work (perhaps messed up, but still an attempt) on intel generated an error about length not being the same or some such, and that being a violation of the f03 standard somewhere. Didn't investigate too deeply. I'm now going forward with the array specification version character(kind=C_CHAR) :: blah(10) = (/ 'b','l','a','h',...... /) since it seems to work on the places I've tried it. Any guess when this ICE might get some attention and into a release version? Thanks for your help, and the pointer about the kind=C_CHAR things that I was not doing correctly. Andy On Dec 6, 2011, at 8:59 AM, sgk at troutmask dot apl.washington.edu wrote: > 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. > > -- > Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email > ------- You are receiving this mail because: ------- > You are on the CC list for the bug. > You reported the bug.