Array boundary checking & Fortran <> C translators

Frank J. Henigman fjhenigman at watcgl.waterloo.edu
Sat Feb 3 06:15:52 AEST 1990


Your problem arises from the fact that the C compiler does not allow floats
as formal parameters - they are converted to doubles.  Thus, the variable
"b" in "subtestc" is actually a double even though it is declared as float.

The following code demonstrates this behaviour.

-----------------------------------------------------------------------------
bar(fp)
  float *fp;
  {
  printf("%f <--- `wrong'\n", *fp);
  }

foo(fpf)
  float fpf;
  {
  bar(&fpf);
  }

main()
  {
  float f = 9876.1234;
  printf("%f <--- right\n", f);
  foo(f);
  }
-----------------------------------------------------------------------------

9876.123047 <--- right
6.102790 <--- `wrong'

-- 
fjhenigman at watcgl.uwaterloo.ca                       Computer Graphics Lab
fjhenigman at watcgl.waterloo.edu   Frank J. Henigman   University of Waterloo
 ...!watmath!watcgl!fjhenigman                       Waterloo, Ontario, Canada



More information about the Comp.sys.sgi mailing list