From: glen herrmannsfeldt on 9 Jun 2010 13:49 Richard Maine <nospam(a)see.signature> wrote: > david <deyv(a)free.fr> wrote: >> It seems that it is possible in fortran to give a function name >> to a subroutine/function, to call it later. > I'm confused as to what you are saying here. No, it is not possible to > give a function name to a subroutine. Functions and subroutines are > separate. Some compilers might not catch the error, but it *IS* an error > to invoke a function as a subroutine or vice versa. That isn't what I first thought he was trying to do. As this feature is more commonly used for functions, some descriptions of it might be written that way. Also, note that, at least in the Fortran 66 and Fortran 77 versions that there is no difference in the calling program (the one supplying the name). But it seems that wasn't the question. Also, note that C has functions but not subroutines, so one with a C background might be confused on the difference. >> Is it possible to give a subroutine adresse to a >> subroutine/function, to call it later ? I believe you mean procedure pointers. > Again, subroutines and functions are separate. Both are procedures, > and can do many of the same kinds of things, but you cannot > change a subroutine into a function. > It sounds somewhat like you are asking for procedure pointers, which are > new to the standard in f2003. Those do allow you to pointer assign a > procedure in one place and then reference it in another. But they have > nothing to do with confusing subroutines and functions. The Fortran 66 feature, passing a subroutine or function name as an actual argument, is often used for routines to do numerical integration, zero finding, or extrema finding. Those tend natrually to reference functions, and don't require the ability to save such for later. You can nest routines such that the ability is passed to a third, fourth, or deeper routine, but, until Fortran 2003, you can't save one for later use. For the OP, note that for C interoperability C (void) functions correspond to Fortran SUBROUTINEs, while other function types correspond to FUNCTIONs. -- glen
From: david on 11 Jun 2010 18:05
Thanks for your clarifications. -- david |