Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
From: will@fast.ucolick.org (William Deich)
Subject: Re: C calling Fortran 77 shared library on OSF/1 (or DUnix ?)
Date: 1996/05/07	[thread overview]
Message-ID: <4mo2h2$cq1@darkstar.UCSC.EDU> (raw)
In-Reply-To: 4mg704$qbj@ictpsp10.ictp.trieste.it


In article <4mg704$qbj@ictpsp10.ictp.trieste.it>,
Sergio Gelato <gelato@oort.ap.sissa.it> wrote:
>In article <4m9s2v$f6u@newton.cc.rl.ac.uk>,
>Rachel Kay Street <R.K.Street@rl.ac.uk> wrote:
>>2) Also any one tried to mix character*(*) array(length) and char *array[]
>>   (or char **array) when making calls from C into Fortran 77 functions ?
>
>I don't know about DEC's Fortran for OSF/1, but that particular mix is
>unlikely to work under other Unix'y implementations.

Actually, that mix will work under most flavors of Unix.  Among those
Unix's with which I am familiar, Fortran compilers under BSD 4.x,
SunOS, Solaris, OSF/1, AIX, and HP-UX, all support the BSD f77
convention for passing storing and passing [arrays of] character
strings.  (HP-UX and AIX have compile-time switches that let you select
between BSD's f77 string-passing convention and another convention.)
The BSD f77 rule is that a pointer to the start of the data is passed
in the argument's normal position in the calling list, and the length
of a character string is attached as an extra argument at the end of
the argument list.

>The equivalent of
>a Fortran CHARACTER array (CHARACTER*(N) array(length)) is usually something
>like char array[length][N], or in some cases char array[length*N].
>(On machines that are not byte-addressable, I would beware if N is
>not a multiple of the word/byte size ratio.)

I am pretty sure (but I don't have a Fortran manual handy to check on this)
that the rules for Fortran EQUIVALENCE statements between character strings
and character arrays guarantees that this layout holds for all Fortran
implementations.  (That is, an array of character strings is laid out in
memory with one character string immediately following the previous.)

-Will

William Deich
UCO / Lick Observatory   |  Internet: will@ucolick.org
University of California |  Phone: (408) 459-3913



  reply	other threads:[~1996-05-07  4:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-02  4:00 C calling Fortran 77 shared library on OSF/1 (or DUnix ?) Rachel Kay Street
1996-05-02  4:00 ` @#$%!?!
1996-05-04  4:00 ` Sergio Gelato
1996-05-07  4:00   ` William Deich [this message]
1996-05-08  4:00     ` Sergio Gelato
1996-05-06  4:00 ` Steve Lionel
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox