Drew McCormack wrote:
> I think it can be done
Not in generic Fortran--it needs to be to a small degree compiler specific. I
have my own tools to do these things for the three compilers I use.
> 1) A means of storing pointers to procedures in a data structure. I
> know this is not directly supported, but is there some back door to
> achieving this (other than C)?
It might work with some compilers to lie about the interface and say an
argument of an external procedure is a dummy procedure where in reality it is
an integer. At some point or other C must be used though to actually get the
address and store it in an integer, or some compilers support VAX or other
extensions which have such an "address of" procedure. Writing it in C is the
easiest thing though!
I routinely use pointers to procedures as members of my derived types (this is
in F2003 of course :-)
> 2) Procedures that effectively take generic pointers (ie like C's
> void*) to memory as arguments. Since Fortran is pass by reference, I
> should be able to achieve this as long as I avoid using an explicit
> interface, which will enforce strong typing.
Yes, but a lot of routines are required to have an explicit interface, so at
some point you will write a procedure that cannot be called without the
explicit interface (in which case you could lie about it). The better
solution is to implement your own version of F2003's C_LOC, which returns the
address of any scalar or contiguous array (regardless of the type), and
simply write fake interfaces for a generic C procedure whenever you need to
use it with a new type. Quite a bit of work, but there is not much that can
be done.
> 3) Procedures that can have a variable number of arguments (like "..."
> in C).
I have no idea what this has to do with OO, but I do not know of any way to do
this with any compiler I've used.
> Can anyone give me pointers or suggested solutions to one or more of
> these requirements?
Unless there is a better reason then "want to see if it works", I suggest
waiting for F2003 or choosing a different strategy :-)
Best,
Aleksandar
|