On 2013-05-20, Richard Maine <nos...@see.signature> wrote:
> Sean O'Donnelly <
sodo...@yahoo.co.uk> wrote:
> That's correct.
>
>> First of all the copy I've got at 12.5.2.1 speaks about effects of intent.
>> The gfortran message probably should have pointed us to 12.5.2.2.
>
> It is probably citing the section of f2003. The section numbering there
> is slightly different.
It should be citing f95 and I should have written I specifed -std=f95
-pedantic -Wall on the compilations.
We've got a few dozen modules that have been working this way with an
earlier gfortran. The problems began when we recently upgraded to a newer
version and the old code built with all the warnings we could find starting
giving us errors.
> "If RESULT is not specified, the result variable is <function-name> and
> all occurances of the function name in <execution-part> statements in
> the scoping unit are references to the result variable."
I read this a half dozen times but refused to believe it. It seems a bit odd
to me the standard would call for this without specifying the semantics
clearly. What I gather from your answer and from going over the standard
again is with so-called "direct recursion" that is invoking the function
from within the function then it's required to specify a result-variable.
Otherwise you can have a recursive case where A calls B and B calls A and
then inside B the invocation of A isn't problematic according to the
standard and doesn't require a result variable. I say there shouldn't be two
ways to do this. That's sloppy and confusing and unbefitting Fortran! Give
us one simple way that always works. Yes I realize an explicit result-value
will always work but that is quite ugly and verbose when return (result)
would allow us not to specify a result-value and also prevent ambiguity in
all cases.
If I've gotten it this time then I think this could have been done a lot
better and it even seems like an effort to be different for the sake of
being different. I don't understand the point of a return statement when it
could have been used as a function to specify the return value thereby
getting us past this particular mess. It's unnecessarily complicated to have
to specify a result-value in some cases and not others.
recursive function ideal (x)
..
return (expression)
end function ideal
is a lot better, more intuitive etc. than
recursive function farfromideal (x) result (y)
..
..
if (bad-input) return
y = x(some_calculation)
end function farfromideal
This is something other languages have done correctly and simply. Why the
hoop-jumping specification of this?
Older gfortran doesn't have a problem with the code nor all of our other
code and ifort and other compilers we tried all support all or various bits
of this the way we coded it years ago. Maybe this is something the standards
team could look into. Having to code an explicit result-value some times and
not others and having the complexity of allowing the user to specify a
unique result-value as opposed to using the function-name which is quite a
bit more obvious, seems quite sloppy and unnecessary.
> You have an occurance of the function name in an <execution-part>,
> therefore by the above, that is a reference to the result variable. But
> it is not valid syntax for a reference to the result variable.
> Therefore, your code is invalid. It is obviously intended to be a
> recursive function reference instead.
Yes indeed, it's so obvious that several compilers did what we wanted with
it. Others, not all the time.
> That's exactly the kind of situation where you must specify RESULT.
> Otherwise, there are cases where it can be ambiguous what is intended.
> In your particular case, it isn't ambiguous, as the syntax is not valid
> for a reference to the result variable. Allowing the unambiguous cases
> is an extension to the standard.
I don't know what an ambiguous case would be but given several compilers do
understand the code it would seem they could flag ambiguous cases and accept
the vast majority of cases that I would expect are not ambiguous. Again this
is something C and other languages have managed to do fairly cleanly despite
their other sadistic characteristics. I didn't expect something like this to
be so crudely designed. And the implementors seem to agree with me to some
extent else they wouldn't have given us a way round it in some or all cases.
Cheers,
Sean