[comp.lang.fortran] f2c used as fortran error checker: one experience

ajayshah@aludra.usc.edu (Ajay Shah) (08/28/90)

In this demo below, f2c traps one of the few million problems with
fortran: not checking for the number of parameters across call,
but isn't able to find inconsistent types.  Any ideas on how that
is to be done?  

I put everything into one file here, how does one make it work
across a lot of files?  Even checking for number of parameters
would be useful to me right now.


Script started on Thu Aug 23 12:59:25 1990
[prc 5] ls
1.f		2.f		response
[prc 6] cat 1.f

	implicit undefined(a-z)
	integer i
	double precision x, y
	call test(x,i,y)
	stop
	end

	subroutine test(x,y)
	double precision x, y
	return
	end

[prc 8] f2c < 1.f
   MAIN:
   test:
Warning on line 11: inconsistent calling sequences for test:
	here 2, previously 3 args and string lengths.
/*  -- translated by f2c (version of 19 June 1990  0:42:57).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Main program */ MAIN__()
{
    /* Builtin functions */
    /* Subroutine */ int s_stop();

    /* Local variables */
    extern /* Subroutine */ int test_();
    static integer i;
    static doublereal x, y;

    test_(&x, &i, &y);
    s_stop("", 0L);
} /* MAIN__ */

/* Subroutine */ int test_(x, y)
doublereal *x, *y;
{
    return 0;
} /* test_ */

[prc 9] cat 2.f

	implicit undefined(a-z)
	integer i
	double precision x, y
	call test(x,i)
	stop
	end

	subroutine test(x,y)
	double precision x, y
	return
	end

[prc 11] f2c < 2.f
   MAIN:
Warning on line 7: local variable y never used
   test:
/*  -- translated by f2c (version of 19 June 1990  0:42:57).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Main program */ MAIN__()
{
    /* Builtin functions */
    /* Subroutine */ int s_stop();

    /* Local variables */
    extern /* Subroutine */ int test_();
    static integer i;
    static doublereal x;

    test_(&x, &i);
    s_stop("", 0L);
} /* MAIN__ */

/* Subroutine */ int test_(x, y)
doublereal *x, *y;
{
    return 0;
} /* test_ */

[prc 12] exit
script done on Thu Aug 23 13:00:18 1990


-- 
_______________________________________________________________________________
Ajay Shah, (213)747-9991, ajayshah@usc.edu
                              The more things change, the more they stay insane.
_______________________________________________________________________________

gl8f@astsun.astro.Virginia.EDU (Greg Lindahl) (08/28/90)

In article <11678@chaph.usc.edu> ajayshah@aludra.usc.edu (Ajay Shah) writes:
>
>In this demo below, f2c traps one of the few million problems with
>fortran: not checking for the number of parameters across call,
>but isn't able to find inconsistent types.  Any ideas on how that
>is to be done?  

Run the program through f2c -A -P, then edit the .c file to include
the prototypes generated by f2c, then run it through an ANSI C
compiler, such as gcc.

--
"In fact you should not be involved in IRC." -- Phil Howard

mwm@a.gp.cs.cmu.edu (Mark Maimone) (08/28/90)

The way to do parameter type checking is to run f2c with the "-P" option.
This will generate prototype files, listing every function with a typed
argument list.  The next time you run f2c, it will use the prototypes
generated on the first pass to verify the number and types of parameters.

I noticed that even the "-P" option didn't catch your int passed to a float.
You might want to get the latest version that incorporates the following
change (thanks to David Gay):

Tue Aug 28 01:56:44 EDT 1990:
  Fix bug in warnings of inconsistent calling sequences: if an
argument to a subprogram was never referenced, then a previous
invocation of the subprogram (in the same source file) that
passed something of the wrong type for that argument did not
elicit a warning message.
-- 
----------------------------------------------------------------------
Mark Maimone				phone: (412) 268 - 7698
Carnegie Mellon Computer Science	email: mwm@cs.cmu.edu
grad student, vocal jazz and PDQ Bach enthusiast