[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug fortran/45466] Bus Error: C program calls Fortran Function which has returned value as Characte
From:       "mikael at gcc dot gnu dot org" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2010-08-31 23:36:50
Message-ID: 20100831233650.4610.qmail () sourceware ! org
[Download RAW message or body]



------- Comment #7 from mikael at gcc dot gnu dot org  2010-08-31 23:36 -------
(In reply to comment #5)
> (In reply to comment #2)
> > Try compiling with -fdump-tree-original and inspecting the
> > expected argument lists.  You really don't want to use a
> > function here.  Use a subroutine.
> >
> > include <stdio.h>
> >
> > void requestdouble_(double*, double*, char *, int *len);
> >
> > int main()
> > {
> >     char str[20];
> >     int len;
> >     double lat.0;
> >     double lon .0;
> >     requestdouble_(&lat, &lon, str, &len);
> >     return 0;
> > }
> > subroutine requestdouble(rlat,rlng,str)
> >   IMPLICIT NONE
> >   REAL(KIND=8), INTENT(IN) :: rlat ! - latitude -
> >   REAL(KIND=8), INTENT(IN) :: rlng ! - longitude -
> >   CHARACTER(LEN=*) :: str
> >   PRINT *, ' requestdouble rlat=', rlat,' rlng=', rlng
> >   str='1111111111111111'
> >   RETURN
> > END subroutine requestdouble
> >
> Thanks. I do know how to work around it with subroutine which I already did in
> my program. But it doesn't explain why 4.1.2 version allows return character
> string from function. Our program works well until the gcc upgrade.
> Is this new standard?
>
This is internal plumbing you should not be relying on, specific to the
compiler and to the compiler version (though for gfortran it has been unchanged
for some time).
The note 15.22 from the fortran standard shows an example how to operate
properly between C and fortran with subroutine character parameters.
It doesn't deal with function return values though.
For sure you need the bind(c) attribute on your function and probably explicit
character length too.


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?idE466

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic