Re: Basic question on local variable



glen herrmannsfeldt wrote:
Gary Scott wrote:
Brooks Moses wrote:
Do the compiler-specific extensions to pass by value get around this problem, by allowing the argument to be modified in the function?

Not to my knowledge.

Yes, as far as I know Fortran never adopted that ability, and even if it did guarantee to pass a temporary, as far as I know you are still not allowed to modify it. Fortran compilers are allowed to optimize out the parenthesis in y = addten( (x) ), or even the expression in

y = addten( x+0 )

Right, and I definitely agree that it's not allowed with that syntax. I'm asking about the non-standard %VAL type things, and what they did. Whether modifying the temporary they create (assuming that's how they work) is allowed would be outside the scope of the standard....

Maybe it could be added for 2008.

Actually, it's already been added in F2003 -- see the VALUE keyword that Reinhold Bader mentioned. When a dummy argument is declared with the VALUE attribute, the function acts as if it has received a temporary variable with a copy of the actual argument value (with the usual caveats that the compiler need not be implemented exactly like that), and you are explicitly permitted to modify the dummy-argument variable.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
.


Loading