🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51937

Re: calling gcc compiled routines from SUNOS fortran

#51937
From: Don &
Date: Thu, 11 Mar 1993 21:45
26 lines
2008 bytes
>>>>> In article <1993Mar11.133051.11006@draco.macsch.com>, B_engelenburg@macsch.com writes:

BE> i am using gcc 2.2.3 on a Sun Sparcstation and i have written some
BE> routines in C but know I want to call them from FORTRAN.

I have done this.  A C function to be called as the fortran subroutine,
"foo" or "FOO" with two integer arguments should be declared in C:

  void foo_ (int*, int*)

Note that an underscore is appended to the name (the Sun Fortran
compiler does this), the name is lower case, and arguments are
passed by reference rather than by value (this is the default
way of passing arguments).  Arrays are also passed by reference,
by passing a pointer to the first member (as in C).  Fortran
"CHARACTER*" variables are more difficult since the Fortran compiler
adds a hidden argument to pass the lenth of the string.  I recommend
against attempting to pass strings.  Set up an array of integers
to pass and do translations on either side.  It's more portable.

None of the above depends on gcc vs some other C compiler.  It
is imposed by the fortran implementation.  It may be different on
other machines or with other fortran compilers.

Don Bashford
bashford@scripps.edu
Technical Details
Message-ID: <BASHFORD.93Mar11134601@griffy.scripps.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!howland.reston.ans.net!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!riscsm!usenet
References: <1993Mar11.133051.11006@draco.macsch.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,4cf501b3263eb009
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-03-11 14:42:24 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!howland.reston.ans.net!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!riscsm!usenet
From: bashford@scripps.edu (Don &)
Subject: Re: calling gcc compiled routines from SUNOS fortran
In-Reply-To: B_engelenburg@macsch.com's message of Thu, 11 Mar 93 13:30:51 GMT
Message-ID: <BASHFORD.93Mar11134601@griffy.scripps.edu>
Followup-To: gnu.gcc.help
Sender: usenet@riscsm.scripps.edu
Organization: The Scripps Research Institute, La Jolla, CA, USA
References: <1993Mar11.133051.11006@draco.macsch.com>
Date: Thu, 11 Mar 1993 21:45:57 GMT
Lines: 26