Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: scjones@sdrc.UUCP (Larry Jones)
Subject: Re: Problem calling a C function from Fortran
Date: 21 Aug 88 16:35:27 GMT	[thread overview]
Message-ID: <353@sdrc.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.

Well, the problem is actually calling a FORTRAN subroutine from C, but read on.
 
< I'm passing two arguments to a C function called "test".  The first one is 
< an integer*4 varaible and the second one is an external function.  The first 
< argument gets passed ok but the external function "dbl" does not seem to get 
< passed ok.

Sure it does, you just called it wrong.
 
< The C function requires the address of where the function "dbl" starts so
< I'm passing the value of the address of the function "dbl" to the C function
< "test" but it does not seem to work.  I'm wondering what Fortran does when you
< try and get %loc(dbl).  Is this really the address of where this function 
< starts?  What am I doing wrong?  Any help would be appreciatted.  This is a
< test program I'm trying out which I need to use in another bigger program.
< 
< Thanks,
< Nate Okinaka (206)773-2687
< 
< The following is the error message I get when I run the program:
< -----------------------------------------------------------------------------
< [okinaka]> r ext
< %loc(dbl) =        4848
< %loc(dbl) in hex =    12F0
< iangle =          90
< iangle in hex =      5A
< This is a test of external function
< x = 90, f = 4848 (decial)
< x = 5a, f = 12f0 (hex)
< %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

Well, the traceback shows that your FORTRAN main program did call your C
function which then called the FORTRAN subroutine so that's not the problem.
The problem is that when the C function calls the FORTRAN subroutine, it passes
the VALUE of the argument instead of the ADDRESS.  When the FORTRAN subroutine
tried to access the variable, it used the value as an address and tried to
get the value stored there and that's what caused the access violation.
Just pass the address instead and everything will work fine.

----
Larry Jones                         UUCP: uunet!sdrc!scjones
SDRC                                      scjones@sdrc
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150                  AT&T: (513) 576-2070
Nancy Reagan on superconductivity: "Just say mho."


  reply	other threads:[~1988-08-21 16:35 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 [this message]
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.
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