Variable number of parameters 
Author Message
 Variable number of parameters

Hello,

I am porting fortran 77 code from VMS to Solaris 2.3.  The VMS code makes
extremeley heavy use of a subroutine consisting of a single VAX assembly
language instruction which peaks at the stack to determine how many arguments
a subroutine was called with to allow variable numbers of parameters to
be passed to the same routine.  Needless to say, this is very difficult
to port.

I have been using %LOC(PARAMETER).NE.0 to determine if a parameter was defined
or not, but I would like a way to determine the number of parameters passed.
For example...

        CALL FOO(A,B)
        CALL FOO(A,B,,D)

In the first invocation, FOO could call some routine to determine that two
parameters had been passed to it.  In the second invocation the same routine
would indicate that 4 parameters had been passed, and %LOC could be used
to find out that the third parameter was defaulted.

Any help in this matter would be gratefully appreciated.

--
Quetzalcoatl Bradley



Wed, 10 Sep 1997 06:42:09 GMT  
 Variable number of parameters
If you are using F90, variable length arguments can be handled easily.  If
you are using Fortran 77, then this might be a little tough

I would find out how many arguments FOO could take AT A MAXIMUM, and
define some constants to indicate that when FOO is called, ignore those
variables that you don't want processed.  For example:

program test

c Assume the IGNORE variables (one for real, integer and character) are
c in a common block somewhere.

real x
call foo (IGNORE_REAL, x,IGNORE_INT)

stop
end

subroutine foo(real a,real b, integer  c)

if (a.ne.IGNORE_REAL) then
   do something
endif

.....

return
end

The trick is to make sure you choose values for the IGNORE variables that
will not be used in the subroutines.  You also have to be careful to make
sure the IGNORE variables are not modified by any subroutine (I always
wished FORTRAN had a const modifier like C).

I realize that this may be prohibitive if you have a subroutine that can
accept many many arguments in the worst case, but this has always worked
well in my applications.

Steve Szyszkiewicz

"When things spin around, things come undone.  Welcome to Earth third rock
from the sun" (Joe Diffy tune)



Wed, 10 Sep 1997 21:35:32 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Variable number of parameters possible?

2. Variable Numbers of Parameters in Fortran Calls

3. How to prototype a variable number of parameters C function in CW?

4. Number of Parameters

5. on determining number of parameters actually passed

6. How to get number of actual parameters in subroutine

7. External Call with variable parameter list

8. J and OLE (Excel): variables in xlreadr parameters?

9. ext. command with awk variable as parameter

10. Pass an AWK variable to a pipeline program as a parameter

11. passing ?use variables as a parameter

12. Sending a command line parameter %1 to a variable in my clarion program

 

 
Powered by phpBB® Forum Software