|
|
Up |
|
|
  |
Author: K-9K-9 Date: May 5, 2008 19:55
Hi guys....I've spent the whole night trying to figure out about this
question. Please help me if you have any clue. Thanks a lot.
The code is very easy. I'm trying to call a fortran function from C.
The code is as follow:
=========C code=========
#include "stdio.h"
extern float r_ (int * d, float *b);
main ()
{
float a = 1.5, b = 1.05, c = 1;
int d = 2;
c = r_ (&d, &b);
printf ("%%f\n", c);
}
==========Fortran Code===========
real function r(m,t)
integer m
real t
|
| Show full article (3.62Kb) |
|
| | 17 Comments |
|
  |
Author: e p chandlere p chandler Date: May 5, 2008 20:26
On May 5, 10:55 pm, K-9 gmail.com> wrote:
> Hi guys....I've spent the whole night trying to figure out about this
> question. Please help me if you have any clue. Thanks a lot.
>
> The code is very easy. I'm trying to call a fortran function from C.
>
> The code is as follow:
>
> =========C code=========
> #include "stdio.h"
>
> extern float r_ (int * d, float *b);
>
> main ()
> {
> float a = 1.5, b = 1.05, c = 1;
> int d = 2;
> c = r_ (&d, &b);
> printf ("%%f\n", c);
> ...
|
| Show full article (1.51Kb) |
|
| | no comments |
|
  |
Author: K-9K-9 Date: May 5, 2008 20:35
Good question. I'm trying to use g77 because i'm trying to develop
some fortran77-only code. Of course yes i can go with gfortran. I was
just curious to see the reason.
Thanks.
On May 5, 11:26 pm, e p chandler juno.com> wrote:
> On May 5, 10:55 pm, K-9 gmail.com> wrote:
>
>
>
>
>
>
>
>> Hi guys....I've spent the whole night trying to figure out about this...
|
| Show full article (1.81Kb) |
| no comments |
|
  |
Author: Greg LindahlGreg Lindahl Date: May 5, 2008 21:22
>Good question. I'm trying to use g77 because i'm trying to develop
>some fortran77-only code. Of course yes i can go with gfortran. I was
>just curious to see the reason.
Check out the f2c-abi. On x86 and x86-64, this is the difference between
g77 and gfortran's calling conventions.
-- greg
|
| |
| no comments |
|
  |
Author: Craig PowersCraig Powers Date: May 6, 2008 10:34
e p chandler wrote:
> 2. At some point g77 diverged from gfortran. They no longer (IIRC)
> have the same calling conventions.
I don't remember the exact set of options required, but I believe one
can make gfortran use the g77 calling convention. I don't think it's
the default, though.
|
| |
| no comments |
|
  |
Author: Steven G. KarglSteven G. Kargl Date: May 6, 2008 10:38
In article <482096a8$0$9832$a726171b@ news.hal-pc.org>,
Craig Powers hal-pc.org> writes:
> e p chandler wrote:
>> 2. At some point g77 diverged from gfortran. They no longer (IIRC)
>> have the same calling conventions.
>
> I don't remember the exact set of options required, but I believe one
> can make gfortran use the g77 calling convention. I don't think it's
> the default, though.
-ff2c is the option. g77's calling convention is actually the
f2c calling convention bacause Craig Burley re-used the f2c
run-time library.
|
| |
| no comments |
|
  |
Author: Charles ColdwellCharles Coldwell Date: May 6, 2008 20:10
lindahl@ pbm.com (Greg Lindahl) writes:
>>Good question. I'm trying to use g77 because i'm trying to develop
>>some fortran77-only code. Of course yes i can go with gfortran. I was
>>just curious to see the reason.
>
> Check out the f2c-abi. On x86 and x86-64, this is the difference between
> g77 and gfortran's calling conventions.
In that case, does this declaration fix the OP's code:
extern double r_ (int * d, float *b);
i.e., in the C code, declare the return value to be double, but
maintain the "real function r(m,t)" definition in the Fortran code
compiled by g77.
Chip
|
| Show full article (0.86Kb) |
| no comments |
|
  |
Author: Catherine Rees LayCatherine Rees Lay Date: May 7, 2008 01:47
K-9 wrote:
> Good question. I'm trying to use g77 because i'm trying to develop
> some fortran77-only code. Of course yes i can go with gfortran. I was
> just curious to see the reason.
>
> Thanks.
Real functions have always been bizarre for reasons I never quite
understood, but which had to do with there being no standard convention
for how the return value is passed. Even in otherwise compatible object
files made by two different compilers they might not work.
At the point that I discovered this particular little weirdity, I just
gave up using them in mixed language programming - it wasn't worth the
hassle of never knowing if they would work.
Catherine.
--
Catherine Rees Lay
Polyhedron Software Ltd. Registered Office: Linden House,
93 High St, Standlake, Witney, OX29 7RH, United Kingdom.
Registered in England No.2541693. Vat Reg No. GB 537 3214 57
|
| |
| no comments |
|
  |
Author: Ingo ThiesIngo Thies Date: May 13, 2008 05:09
e p chandler wrote:
> 3. Who cares? Is there a compelling reason to use g77, which is no
> longer actively maintained, instead of gfortran, which is under active
> development?
Yes, there is. For F77 code g77 is by far faster than gfortran. I found
a factor of about three for one oy my simulation programs (I can't
remember which, but most probably something with N-body calculations).
If compiled with g77 it took about 20 seconds for a test run. The same
code, but compiled with gfortran, needed about 70 sec. As far as I
remebmer, the ratio was not really better with optimisation options
(BTW, what is the reason for that?).
Ingo
|
| |
| no comments |
|
  |
|
|
  |
Author: stevenb.gccstevenb.gcc Date: May 13, 2008 05:50
On May 13, 2:09 pm, Ingo Thies wrote:
> e p chandler wrote:
>> 3. Who cares? Is there a compelling reason to use g77, which is no
>> longer actively maintained, instead of gfortran, which is under active
>> development?
>
> Yes, there is. For F77 code g77 is by far faster than gfortran. I found
> a factor of about three for one oy my simulation programs (I can't
> remember which, but most probably something with N-body calculations).
> If compiled with g77 it took about 20 seconds for a test run. The same
> code, but compiled with gfortran, needed about 70 sec. As far as I
> remebmer, the ratio was not really better with optimisation options
> (BTW, what is the reason for that?).
>
> Ingo
|
| Show full article (1.04Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|