From: ralf.schaa on 23 Dec 2009 00:09 I'm playing with some of the new features in F2003 and I try to understand how to use type-bound procedures. I came up with the example below which compiles and executes with ifort 11.1 - my question are: 1) is "call t%test(t)" from the code below valid? Looks like a recursion. 2) when omitting "nopass", the compiler complaints ( 'The number of actual arguments cannot be greater than the number of dummy arguments.' ) But why the need for "nopass" since clearly i pass something? p.s. a search for "CLASS" and also "NOPASS" in the intel fortran help did not show any results...(ifort 11.1 and visual studio 2008, both evaluation) cheers module class_test implicit none private type, public :: t_test integer :: dummy contains procedure, nopass :: test ! why nopass? end type t_test contains subroutine test( test_this ) class(t_test) :: test_this test_this%dummy = 1 end subroutine test end module class_test program test use class_test type(t_test) :: t call t%test(t) ! a bootstrap? print*,t%dummy end program test
From: Richard Maine on 23 Dec 2009 00:43 ralf.schaa <ralf.schaa(a)gmail.com> wrote: > 1) is "call t%test(t)" from the code below valid? Looks like a > recursion. Yes, it is valid. Looks nothing at all like a recursion. Recursion is when a procedure invokes itself (directly or indirectly). I don't see what procedure you think this looks even close to invoking itself. There is only one procedure anywhere in sight and it doesn't invoke any procedures at all, much less itself. I think maybe you are using "recursive" with some meaning other than the usual one. Perhaps you are using it as a synonym for "redundant", which is a completely different thing. Yes, there is some redundancy here in specifying t twice. That is the common redundancy that passed-object dummy arguments can avoid. > 2) when omitting "nopass", the compiler complaints > ( 'The number of actual arguments cannot be greater than the number of > dummy arguments.' ) > But why the need for "nopass" since clearly i pass something? Nopass doesn't mean that you pass nothing. If that's all it meant, it would be completely superfluous, as it would be evident in the call just by putting nothing there. NOPASS means that there is no passed-object dummy. A passed-object dummy is a dummy argument that associates with the object used in the invocation rather than from something in the actual argument list. That probably sounds confusing. I could recommend a book that explains it in more detail :-) But it could be illustrated in your example by taking the nopass off and then doing call t%test The passed-object dummy then associates with t. Do *NOT* also put t in the actual argument list. That would be looking for a second dummy argument (which you don't have). > module class_test > > implicit none > private > > type, public :: t_test > integer :: dummy > contains > procedure, nopass :: test ! why nopass? > end type t_test > > contains > > subroutine test( test_this ) > class(t_test) :: test_this > test_this%dummy = 1 > end subroutine test > > end module class_test > > program test > use class_test > type(t_test) :: t > call t%test(t) ! a bootstrap? > print*,t%dummy > end program test -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
|
Pages: 1 Prev: Spam removal - volunteer? Next: Some matlab -> fortran translation |