a subroutine like READ (variable number of parameters)

a subroutine like READ (variable number of parameters)

I want to make a subroutine like the READ statement. By that I mean, I want to be able to use any number of parameters, and have them be of any type. The function will eventually call a c function which will be emulating the fortran READ statement, but will be getting the data from a C data structure.

So I was wondering if it is possible to make a fortran function that I could use like this:
CREAD (1, '(%i,%i,%d,%c,%d)', int1, int2, double1, char1, double2)
and then use the same subroutine like:
CREAD (1, '(%c,%i,%d,%d)', char2, int1, double1, double2)
etc, etc...

If this can be done, could someone point me in the right direction for some documentation on it?

The statement I'm after is similar to the use of ellipses in c function signatures.

Joel Dawkins

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Fortran doesn't have a variable argument list in the sense that C does. However a decent solution is to make an vector of addresses, something like:

subroutine cread (unit, format, arguments)
integer(DWORD) unit
character(*) format
integer(POINTER_LEN) arguments(0:*)

where the first element of arguments is the variable parameter count. So calling looks something like:

arguments(0) = 5
arguments(1) = LOC(int1)
arguments(2) = LOC(int2)
arguments(3) = LOC(double1)
arguments(4) = LOC(char1)
arguments(5) = LOC(double2)
call cread (1, '(%i,%i,%d,%c,%d)', arguments)


Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui