Article View: comp.sys.dec
Article #5011Re: Problem calling a C function from Fortran
From: Gil Kloepfer Jr.
Date: Mon, 22 Aug 1988 03:47
Date: Mon, 22 Aug 1988 03:47
74 lines
3064 bytes
3064 bytes
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 |
+------------------------------------+----------------------------------------+
Technical Details
Message-ID:
<182@limbic.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!rutgers!att!icus!limbic!gilReferences:
<1134@ssc-bee.ssc-vax.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!rutgers!att!icus!limbic!gil From: gil@limbic.UUCP (Gil Kloepfer Jr.) Newsgroups: comp.sys.dec,comp.lang.fortran,comp.lang.c Subject: Re: Problem calling a C function from Fortran Summary: Arguments in VAX FORTRAN passed by reference Keywords: Fortran, C, external function in Fortran Message-ID: <182@limbic.UUCP> Date: 22 Aug 88 03:47:30 GMT References: <1134@ssc-bee.ssc-vax.UUCP> Reply-To: gil@limbic.UUCP (Gil Kloepfer Jr.) Organization: ICUS Computer Group, Islip, NY Lines: 73