From: gelato@oort.ap.sissa.it (Sergio Gelato)
Subject: Re: C calling Fortran 77 shared library on OSF/1 (or DUnix ?)
Date: 1996/05/04 [thread overview]
Message-ID: <4mg704$qbj@ictpsp10.ictp.trieste.it> (raw)
In-Reply-To: 4m9s2v$f6u@newton.cc.rl.ac.uk
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. 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.)
You then need to pass N as part of the argument list (if calling Fortran)
or retrieve it from the argument list (in a C routine called by Fortran).
The same N applies to all elements of the array.
If you look at the assembly code generated by the compiler for
INTEGER FUNCTION L(S)
CHARACTER*(*) S
L=LEN(S)
END
you should be able to figure out how the string length is being passed.
Reading the Fortran manual may be easier, if you have it.
Alternatively, you could try
#define N 10
char str[N];
int l_();
size_t ll = N;
printf("%d %d %d %d\n", l_(&ll, str), l_(str, &ll), l_(N, str), l_(str, N));
and study what it prints out (if it doesn't dump core, in which case you'll
have to try the possibilities separately).
next prev parent reply other threads:[~1996-05-04 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 [this message]
1996-05-07 4:00 ` William Deich
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