Prev: non printing characters
Next: Fortran problem
From: Uno on 6 Jul 2010 19:33 http://i48.tinypic.com/27wyvpg.png I have read many times about fortran-c interop in c.l.f. and wanted to search for these articles I have read. The screenshot shows how utter this failure was. q1) How do I do a keyword search of c.l.f.? -- Uno
From: e p chandler on 6 Jul 2010 20:18 "Uno" wrote > I have read many times about fortran-c interop in c.l.f. and wanted to > search for these articles I have read. The screenshot shows how utter > this failure was. c interop real site:comp.lang.fortran in the google search box comes up empty > How do I do a keyword search of c.l.f.? Try this instead c interop real site:groups.google.com/group/comp.lang.fortran
From: Uno on 7 Jul 2010 00:29 e p chandler wrote: > Try this instead > c interop real site:groups.google.com/group/comp.lang.fortran Alright, that does a lot better. (I entered that into my linuxlog.) http://www.google.com/search?hl=en&as_q=+c+interop+real+site%3Agroups.google.com%2Fgroup%2Fcomp.lang.fortran+&as_epq=&as_oq=&as_eq=&num=10&lr=&as_filetype=&ft=i&as_sitesearch=&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images So I poked around and didn't find exactly what I want there. I want a C caller to print out the value of a fortran function that wraps an arctan call: $ gfortran -Wall -Wextra f_pi1.f90 -o out $ ./out 3.1415927 $ cat f_pi1.f90 implicit none ! none of this yet !integer, parameter, public :: sp = kind(1.0) !integer, parameter, public :: dp = selected_real_kind(2*precision(1.0_sp)) !integer, parameter, public :: qp_preferred = & !selected_real_kind(2*precision(1.0_dp)) !integer, parameter, public :: qp = (1+sign(1,qp_preferred))/2*qp_preferred+ & !(1-sign(1,qp_preferred))/2*dp real :: constant, pi constant = 4.0 pi = constant * atan(1.0) print *, pi end program ! gfortran -Wall -Wextra f_pi1.f90 -o out $ A C program that does the same thing is: $ gcc -std=c99 -Wall -Wextra c_pi1.c -o out $ ./out pi is 3.141593 $ cat c_pi1.c #include <stdio.h> #include <math.h> // C will be caller int main() { double d, pi; d = atan(1.0); pi = (4.0)*d; printf("pi is %f\n", pi); return 0; } // gcc -std=c99 -Wall -Wextra c_pi1.c -o out $ q2) If this calculation is done in a posix-compliant environment, are the widths of C's double and fortran's default real related? Short of enlightment by google, I'm left to follow the development in MR&C 14.10. The place where I lose my grip there is with the prototype void simulation(struct pass *arrays); that is called by simulation(&arrays); q3) Why does the MR&C development need the interface listed in figure 14.3 *and* the interface lsited in 14.4? q4) If anyone has any suggestions regarding better search terms for this question, I'm all ears. Thanks for your comment, and cheers, -- Uno
From: Tobias Burnus on 7 Jul 2010 02:07 First, I want to point out that there is some C interoperability documentation at http://gcc.gnu.org/onlinedocs/gfortran/Interoperability-with-C.html Uno wrote: > So I poked around and didn't find exactly what I want there. I want a C > caller to print out the value of a fortran function that wraps an arctan > call. How about something like: function myarctan(x) bind(C,name='myArctan') use iso_c_binding implicit none read(c_double), VALUE, intent(in) :: x real(c_double) :: myarctan myarctan = atan(x) end function myactan and double myArctan (double); .... double x = ... printf("myactan(%e) = %e\n", x, myArctan(x)); > q2) If this calculation is done in a posix-compliant environment, are > the widths of C's double and fortran's default real related? REAL(c_double) == double etc. (using the intrinsic ISO_C_BINDING module of Fortran 2003, cf. http://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html Tobias
From: Uno on 7 Jul 2010 03:16
Tobias Burnus wrote: > First, I want to point out that there is some C interoperability > documentation at > http://gcc.gnu.org/onlinedocs/gfortran/Interoperability-with-C.html > > Uno wrote: >> So I poked around and didn't find exactly what I want there. I want a C >> caller to print out the value of a fortran function that wraps an arctan >> call. > > How about something like: > > function myarctan(x) bind(C,name='myArctan') > use iso_c_binding > implicit none > read(c_double), VALUE, intent(in) :: x > real(c_double) :: myarctan > myarctan = atan(x) > end function myactan I've got a switch problem here, and looking at gcc.pdf and gfortran.pdf in whatever crapass pdf viewer comes with ubuntu is availing me nothing. I'm missing a switch here on the goocher, my commented-out command line: $ cat f_pi2.f90 function myarctan(x) bind(C,name='myArctan') use iso_c_binding implicit none read(c_double), VALUE, intent(in) :: x real(c_double) :: myarctan myarctan = atan(x) end function myarctan ! gfortran -Wall -Wextra f_pi2.f90 -o fortranlib.o $ How do I tell gfortran.exe not to expect main? > > and > > double myArctan (double); > ... > double x = ... > printf("myactan(%e) = %e\n", x, myArctan(x)); > > >> q2) If this calculation is done in a posix-compliant environment, are >> the widths of C's double and fortran's default real related? > > REAL(c_double) == double > > etc. (using the intrinsic ISO_C_BINDING module of Fortran 2003, cf. > http://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html > > Tobias |