From: "Richard Wang" <[log in to unmask]>
Sent: Thursday, January 12, 2006 3:26 PM
> I'd like to ask a style question. As far as I know there are two
> ways to define a function. Is the 2) a better way than 1)?
>
> Richard
>
> 1)
>
> real function test(a)
> real, intent(in) :: a
> a=a+1
> test=a
> end function test
Function (1) is in error: dummy argument A is defined as INTENT(IN).
Therefore it cannot be incremented.
Even if dummy argument A were defined as INTENT(IN OUT),
the effect of incrementing A would not be desirable.
> 2)
>
> function test(a)result(b)
>
> real, intent(in) :: a
> real :: b
>
> b=a+1
>
> end function test
Method (2) is a good way to define the function.
Dummy argument A is not altered, abd the reslt is returned
via B.
|