I have a C program but want to use the FORTRAN NAMELIST feature to <br>
read in initial variable values. I need to know how to declare the <br>
variables in FORTRAN so the linker knows the variables are the same as those used in the C code.
I am giving a program below which can help you. <br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br>The C main program uses the __stdcall keyword to call the Fortran routines with the correct calling convention. The C source must use all-uppercase names for the routines, because this Fortran code does not use the C, STDCALL, or ALIAS attributes. Finally, pass by value and pass by reference are specified explicitly, though pass by reference would have been assumed by default for Fortran.<br><br>/* File CMAIN.C */<br><br>#include <stdio.h><br><br>extern int __stdcall FACT (int n);<br>extern void __stdcall PYTHAGORAS (float a, float b, float *c);<br><br>main()<br>{<br> float c;<br> printf("Factorial of 7 is: %d\n", FACT(7));<br> PYTHAGORAS (30, 40, &c);<br> printf("Hypotenuse if sides 30, 40 is: %f\n", c);<br>}<br><br>C File FORSUBS.FOR<br>C<br> INTEGER*4 FUNCTION Fact <br> INTEGER*4 n [VALUE]<br> INTEGER*4 i, amt<br> amt = 1<br> DO i = 1, n<br> amt = amt * i<br> END DO<br> Fact = amt<br> END<br><br> SUBROUTINE Pythagoras (a, b, c)<br> REAL*4 a [VALUE]<br> REAL*4 b [VALUE]<br> REAL*4 c [REFERENCE]<br> c = SQRT (a * a + b * b)<br> END<br><br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.