Mixed C and fortran
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Mixed C and fortran




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Mixed C and fortran  
Neil Forsythe


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-04 10: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





[ Post a follow-up to this message ]



    Re: Mixed C and fortran  
John Galt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-04 10: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







[ Post a follow-up to this message ]



    Re: Mixed C and fortran  
Chuck Dillon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-04 10: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.





[ Post a follow-up to this message ]



    Re: Mixed C and fortran  
Ara.T.Howard


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-04 10: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 d
o
| not love it. --Dogen
 ========================================
====================================
===





[ Post a follow-up to this message ]



    Re: Mixed C and fortran  
Neil Forsythe


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-21-04 03:32 AM

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@har
p.ngdc.noaa.gov>...
> On Thu, 17 Jun 2004, Neil Forsythe wrote:
> 
>
> the string representation in fortran and c is often a cause of this (besid
es
> 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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:31 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register