Unix Programming - Mixed C and fortran

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > Mixed C and fortran





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Mixed C and fortran
Neil Forsythe

2004-06-17, 5:55 pm

Dear all

Has anyone hade any experence with compiling code that is mixed c and
fortran ( c routines calling fortran routines) using the intel IA-32
compiler and gcc?

I have obtained a program which I can compile and run without any
problems using f77 as the fortran compiler and gcc. However when I
use the intel compiler, although the progran compiles successfully, it
shows "segmantation fault" errors when running.

Is there any specific complier options or runtime flags that need to
be set for the intel compiler to avoid this problem?

Kind Regards

Neil
John Galt

2004-06-17, 5:55 pm


Segmentation fault is a runtime error, not a compile error. It's usually
caused when you try to access memory (e.g. 0x0) that you're not supposed to.
In your case, I'd guess it's because you haven't allocated memory correctly,
or you have rogue pointers, or the pointers being passed by your C routines
to your Fortran routines are somehow being mashed.

HTH, John
"Neil Forsythe" <n.forsythe@qub.ac.uk> wrote in message
news:deae8c94.0406170215.6793c66d@posting.google.com...
> Dear all
>
> Has anyone hade any experence with compiling code that is mixed c and
> fortran ( c routines calling fortran routines) using the intel IA-32
> compiler and gcc?
>
> I have obtained a program which I can compile and run without any
> problems using f77 as the fortran compiler and gcc. However when I
> use the intel compiler, although the progran compiles successfully, it
> shows "segmantation fault" errors when running.
>
> Is there any specific complier options or runtime flags that need to
> be set for the intel compiler to avoid this problem?
>
> Kind Regards
>
> Neil



Chuck Dillon

2004-06-17, 5:55 pm

Neil Forsythe wrote:
> Dear all
>
> Has anyone hade any experence with compiling code that is mixed c and
> fortran ( c routines calling fortran routines) using the intel IA-32
> compiler and gcc?
>
> I have obtained a program which I can compile and run without any
> problems using f77 as the fortran compiler and gcc. However when I
> use the intel compiler, although the progran compiles successfully, it
> shows "segmantation fault" errors when running.


Mixing C and FORTRAN requires some system/compiler specific settings.
The call mechanism across the C-FORTRAN boundary is not standard. I
don't have any experience doing this with gcc but I do with other
compilers on several systems.

One example of the kind of problem that you might be encountering is
that some f77 compilers have an option to add a null terminator byte
immediately after allocated char arrays (e.g. char literals) so that
they can be safely passed directly to a C function. If the code you
have assumes this compiler feature it doesn't protect the C code from
non null terminated strings. So you need to make sure that compiler
option exists and is asserted when you build the FORTRAN code.

I suggest you look at the doc for the f77 compiler you are using and
find whatever doc there is on interfacing to C based binaries. That
will give you an overview of the kinds of issues and problems you can
expect.

Find a makefile (or other build mechanism) that could produce a working
version of the application on some/any system and inspect the compiler
settings used. You'll need access to the doc for the compilers to make
sense of the options.

I also suggest you follow up with the folks in comp.lang.fortran.
There are lots of folks there with experience in this area on many
systems with many different compilers. I'm sure they can tell you
which g/f77 switches to look at.

-- ced

>
> Is there any specific complier options or runtime flags that need to
> be set for the intel compiler to avoid this problem?
>
> Kind Regards
>
> Neil



--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
Ara.T.Howard

2004-06-17, 5:55 pm

On Thu, 17 Jun 2004, Neil Forsythe wrote:

> Dear all
>
> Has anyone hade any experence with compiling code that is mixed c and
> fortran ( c routines calling fortran routines) using the intel IA-32
> compiler and gcc?
>
> I have obtained a program which I can compile and run without any
> problems using f77 as the fortran compiler and gcc. However when I
> use the intel compiler, although the progran compiles successfully, it
> shows "segmantation fault" errors when running.
>
> Is there any specific complier options or runtime flags that need to
> be set for the intel compiler to avoid this problem?
>
> Kind Regards
>
> Neil


the string representation in fortran and c is often a cause of this (besides
memory management issues detailed in other posts). in c strings are null
terminated and in fortran they are not. if fortran code calls c routines
which take strings look into this as a source of error.

cheers.

-a
--
========================================
=======================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it; and a weed grows, even though we do
| not love it. --Dogen
========================================
=======================================
Neil Forsythe

2004-06-20, 10:32 pm

Dear all,

Thank you for you contributions. It has certainly given me a few
ideas about the source of the error

Kind Regards,

Neil

"Ara.T.Howard" <ahoward@noaa.gov> wrote in message news:<Pine.LNX.4.60.0406171526570.520@harp.ngdc.noaa.gov>...
> On Thu, 17 Jun 2004, Neil Forsythe wrote:
>
>
> the string representation in fortran and c is often a cause of this (besides
> memory management issues detailed in other posts). in c strings are null
> terminated and in fortran they are not. if fortran code calls c routines
> which take strings look into this as a source of error.
>
> cheers.
>
> -a

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com