Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!aero!tak From: tak@aerospace.aero.org (Michael L. Takayama) Newsgroups: comp.sys.sgi Subject: Re: Array boundary checking & Fortran <> C translators Message-ID: <65973@aerospace.AERO.ORG> Date: 1 Feb 90 17:15:12 GMT References: <90Jan25.135818est.57895@ugw.utcs.utoronto.ca> Reply-To: tak@aero.UUCP (Michael L. Takayama) Organization: The Aerospace Corporation, El Segundo, CA Lines: 81 If you are calling Fortran subroutines from C, you may want to be aware of the following problem which I ran into: In certain cases, floats do *not* pass correctly to REALs. This problem does not occur with ints to INTEGERs nor with doubles to DOUBLE PRECISIONs. Example code: *** main.c *** main() { double a; float b; int c; a = 1234.5678; /* Assign values. */ b = 9876.1234; c = 121162; /* Call C routine which calls Fortran routine. */ subtestc(a, b, c); } *** subtest.c *** subtestc(a, b, c) double a; float b; int c; { float temp; temp = b; /* This is my work-around. */ /* Call the Fortran routine. */ subtest_(&a, &b, &c, &temp); } *** subtest.f *** SUBROUTINE SUBTEST(A,B,C,TEMP) C DOUBLE PRECISION A REAL B,TEMP INTEGER C C C JUST WRITE OUT THE VALUES C WRITE(*,*) A WRITE(*,*) B WRITE(*,*) C WRITE(*,*) TEMP C RETURN END The output of this program is: 1234.567800000000 <<---- ok for double -> DOUBLE PRECISION 6.102790 <<---- WRONG for real -> FLOAT 121162 <<---- ok for int -> INTEGER 9876.123 <<---- ok for real -> FLOAT using a temporary variable in subtestc() Maybe I am doing something illegal here and just got lucky with the ints and doubles passing correctly (I don't think so - I have about 60 routines mixing C and Fortran which *do* work correctly), but I notified the Hotline and they think it is an undiscovered bug in the Fortran compiler. With deepest sympathies to my fellow multi-lingual programmers - Michael L. Takayama Computer-Aided Engineering Department The Aerospace Corporation