Variable Numbers of Parameters in Fortran Calls 
Author Message
 Variable Numbers of Parameters in Fortran Calls

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.

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.

Hope that somebody can help, thanks.

**********************************************

Opinions are mine and not those of my employer
**********************************************



Mon, 30 Nov 1998 03:00:00 GMT  
 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).



Wed, 02 Dec 1998 03:00:00 GMT  
 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 had a program that simply did a reallocate, copy  
two step for each argument until the call to va_arg() came
back NULL. This assumes that the last argument is not
NULL, which worked fine for me.
Matt


Sun, 06 Dec 1998 03:00:00 GMT  
 Variable Numbers of Parameters in Fortran Calls



Quote:
>> >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 had a program that simply did a reallocate, copy  
>two step for each argument until the call to va_arg() came
>back NULL. This assumes that the last argument is not
>NULL, which worked fine for me.

My own testing shows that it is not reliable. You are also making the
assumption that the last argument is always followed by a NULL pointer,
which is not true in code generated by (my release of) HP's f77.

Quote:
>Matt

--
Note to junk mailers: e-mail to this address will not be read
(but its origin will be logged for possible blacklisting).


Mon, 07 Dec 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Variable number of parameters possible?

2. Variable number of parameters

3. External Call with variable parameter list

4. calling C++ function from Fortran: parameter passing

5. cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3

6. Q:Fortran call C parameter passing

7. FORTRAN dynamic arrays used as parameters of functions called from C++

8. Can you call a C routine with a variable number of arguments from

9. C- Fortran interface - Variable number of arguments

10. Calling Fortran-functions returning complex numbers from C

11. VC++ calling fortran function and fortran function calling a c++ function

12. c++ calling fortran and fortran calling C++

 

 
Powered by phpBB® Forum Software