
Variable Numbers of Parameters in Fortran Calls
Quote:
>I am currently involved in work which re-implements some old
>Fortran system calls in C. Some of the calls specify optional
>fields to the call (eg directive status). Although C can cope
>with variable length argument lists, it cannot find out how
>many parameters were passed, it has to be told (by NULL terminating
>the list for example).
>Does anybody know a way of finding out how many parameters have
>been put in the stack frame (either in C or Fortran)? We don't
>really want to have to re-define the system call to disqualify
>the optional fields.
Who says the parameters are in the stack frame? They could be in
registers. In fact, inspection of an assembly listing from HP f77
on a PA1.1 suggests that HP chose precisely that approach.
I hope it is clear to you that
1. any solution you may find for a particular platform will be non-portable;
2. there need not be a solution at all, unless you are using Fortran 90
(in which case you can give arguments the OPTIONAL attribute and the callee
will be able to test if they are PRESENT, or you can overload the routine
name and supply different implementations for different numbers of arguments).
Quote:
>An example of this is the function MARK (a timer function), which
>is defined as:
>MARK(efn,tmg,tnt[,ids])
>Both of the following are valid calls:
>CALL MARK(EF1,TIME,SECS)
>CALL MARK(EF1,TIME,SECS,STATUS)
>But how do you tell if you've been given the pointer to the STATUS
>variable in order to put a meaningful value in there?
>We are using the f77 compiler supplied with HP-UX 9.05.
On a 700/800 or on a 300/400? I don't have access to the latter, but
on the former the first four arguments, at least, appear to be passed
in registers (26,25,24,23), and I see no generated code that would pass
the argument count. There may still be some hope, though, if you
are willing to decrypt the debug stabs. (I won't do that for you.)
--
Note to junk mailers: e-mail to this address will not be read
(but its origin will be logged for possible blacklisting).