From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!ames!ucbcad!ucbvax!MITRE-BEDFORD.ARPA!emery%aries From: emery%aries@MITRE-BEDFORD.ARPA (David Emery) Newsgroups: comp.lang.ada Subject: re: Fortran and Ada Message-ID: <8711091529.AA12319@aries> Date: Mon, 9-Nov-87 10:29:55 EST Article-I.D.: aries.8711091529.AA12319 Posted: Mon Nov 9 10:29:55 1987 Date-Received: Sun, 15-Nov-87 06:18:14 EST Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: Mary McNabb writes about a problem she has in trying to pass data between Ada and fortran. I think the problem is not with the external object thisandthat, but with the parameter passed to fortran from Ada. In a nutshell, I suspect that she was a bit too clever... One thing in her code that is a bit wierd is the following: value : system.address; procedure fsub(value : system.address); pragma interface (fortran, fsub, "_fsub"); begin value := system.address(3); -- what does this mean? -- if system.address is private, this is -- illegal. -- if system.address is a numeric type, -- then this is the memory address 3. -- this is NOT the address of the constant -- "3" fsub(value); end; Therefore, when calling fortran fsub(i), where I is an integer, and given fortran passing parameters by address, what we have is a reference to memory address 3, which is deep in the kernel, and causes unix to burp! Here is what I think she meant: value : integer; procedure fsub(value : system.address); pragma interface (fortran, fsub, "_fsub"); begin value := 3; fsub(value'address); end; There are some potential problems here, too. The Ada declaration of fsub is procedure fsub(value : in system.address); pragma interface (fortran, fsub, "_fsub"); and the Fortran declaration is subroutine fsub(i) integer i And these may not be the same. In particular, depending on the exact semantics of pragma interface for Fortran, what you may get is 2 level indirect addressing, in the following sense. "fsub is a fortran routine. fortran routines pass all values by address. Therefore, what we give fortran is the address of the parameter. Since the Ada parameter type is system.address, what we will pass fortran is the address of this address. So what we do is the following: 1. allocate some memory (stack or heap), and put the parameter there. 2. pass the address of this memory to fortran So, fortran sees the address of the address of the value, not the address of the value." This interpretation is consistent with the value of I being a very large number when seen in fortran. I is an address somewhere deep in the program (probably on the callers stack...) So, really what I suspect we should have is the following: (Isn't this what she really wants to say???) procedure fsub (value : integer); pragma interface (fortran, fsub, "_fsub"); value : integer; begin value := 3; fsub(value); end; I hope this helps... dave emery emery@mitre-bedford.arpa