Hello,
Stefan Ano wrote:
> I wonder weather the attributes INTENT(IN) and VALUE are combinable? I
> had a short look to the standard (12.4.1.2) and couldn't find
> disqualifiers.
>
> I am thinking of having an elemental function like:
>> ELEMENTAL FUNCTION convert(a) RESULT(b)
>> REAL, INTENT(IN), VALUE :: a
Yes - you may combine them. In Fortran 2003, you even have to - if you
want to use VALUE. In Fortran 2008, VALUE without INTENT(in) is also fine.
Semantically, there is of course a difference: intent(in) means that you
may not change the value - while VALUE creates a copy of the data, which
you may modify, but those changes cannot affect the outside world.
If you think of performance, passing scalar non-character intrinsics by
VALUE is usually better (faster by itself and it might help the compiler
with optimizing). On the other hand, VALUE for arrays, derived types and
arrays involves copying the data, which is in general slower. (For
arrays, the compiler creates a contiguous array by copying which might
be in some cases faster; CONTIGUOUS does the same but avoids copying if
possible.)
In any case, not all compilers support VALUE without INTENT(IN) in PURE
procedures (implied by "elemental", unless IMPURE is used) - nor do many
compilers support VALUE with arrays, character and nonintrinsic data
types, yet.
Tobias
|