From: gil@limbic.UUCP (Gil Kloepfer Jr.)
Subject: Re: Problem calling a C function from Fortran
Date: 22 Aug 88 03:47:30 GMT [thread overview]
Message-ID: <182@limbic.UUCP> (raw)
In-Reply-To: 1134@ssc-bee.ssc-vax.UUCP
In article <1134@ssc-bee.ssc-vax.UUCP> okinaka@ssc-vax.UUCP (Nathan Okinaka) writes:
|>
|>I'd appreciate if anybody out there could help me with a problem I'm having
|>calling a function written in C from a Fortran program on the VAX/VMS.
|>
[Description deleted]
|>Thanks,
|>Nate Okinaka (206)773-2687
|>
|>The following is the error message I get when I run the program:
|>-----------------------------------------------------------------------------
|>%SYSTEM-F-ACCVIO, access violation, reason mask=00, virtual address=0000005A,
|>PC=000012F9, PSL=03C00020
|>%TRACE-F-TRACEBACK, symbolic stack dump follows
|>module name routine name line rel PC abs PC
|>DBL DBL 5 00000009 000012F9
|>TEST test 9 00000039 000013AD
|>EXT$MAIN EXT$MAIN 17 000000AA 000012AA
[Programs deleted]
Nate,
The fact that your program aborted in DBL shows that DBL *is* actually
called (and it is, from looking at your programs). The problem is in the
way you pass the integer*4 number to the C program. Here is a little code
segment to show how to properly pass integer variables between fortran and
C on VMS:
Fortran code:
PROGRAM TEST
INTEGER*4 FVAR
CALL CROUTINE(FVAR)
CALL EXIT
END
C code:
croutine(fvar)
long *fvar; /* note: fortran passes by reference */
{
long cvar;
cvar = *fvar + 10; /* correct referencing of fvar */
f77routine(&cvar); /* must pass cvar to f77 by reference */
/* which is a C pointer */
}
Fortran code:
SUBROUTINE F77ROUTINE(CVAR)
INTEGER*4 CVAR
WRITE(6,*) 'CVAR = ',CVAR
RETURN
END
Your passing of the function with %LOC was perfect, but the way you passed
your integer variables seemed a bit obscure. I have been using C and
FORTRAN this way with success, so this should help.
Hope it did help...
+------------------------------------+----------------------------------------+
| Gil Kloepfer, Jr. | Net-Address: |
| ICUS Software Systems | {boulder,talcott}!icus!limbic!gil |
| P.O. Box 1 | Voice-net: (516) 968-6860 |
| Islip Terrace, New York 11752 | Othernet: gil@limbic.UUCP |
+------------------------------------+----------------------------------------+
next prev parent reply other threads:[~1988-08-22 3:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1988-08-19 17:54 Problem calling a C function from Fortran Nathan Okinaka
1988-08-21 16:35 ` Larry Jones
1988-08-22 20:37 ` String passing (was :Re: " Rajiv Agrawal
1988-08-30 13:15 ` rbt
1988-08-22 3:47 ` Gil Kloepfer Jr. [this message]
1988-08-22 20:55 ` Steven J Kassarjian
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