Re: Optimisation and INTENT
- From: kargls@xxxxxxxxxxx
- Date: Sun, 3 May 2009 10:43:34 -0700 (PDT)
On May 3, 10:14 am, glen herrmannsfeldt <g...@xxxxxxxxxxxxxxxx> wrote:
FX <coud...@xxxxxxxxxxxxx> wrote:
I'm wondering if, in the following testcase, the result of function foo()
is guaranteed by the standard to be zero, or if one could construct a
standard-conforming function bar() such that it is not the case:
integer function foo()
interface
integer function bar(b)
integer, intent(in) :: b
end function
end interface
integer :: b, d, k
b = 12
d = b
k = bar(b)
foo = d - b
end function
The reason I'm asking is because an equivalent C testcase, using pointers
to const-qualified types, does not yield such guarantees. I believe
Fortran does, but I'd like to be sure.
I believe Fortran will also let you modify an intent(in) argument.
The intent is a promise to the compiler that you won't modify
such an argument, and if you do Fortran doesn't make any
guarantees as to the result. That doesn't sound too different
from const in C.
The Standard appears to disagree with you:
The INTENT (IN) attribute for a nonpointer dummy argument specifies
that it shall neither be defined nor become undefined during the
execution of the procedure. The INTENT (IN) attribute for a pointer
dummy argument specifies that during the execution of the procedure
its association shall not be changed except that it may become
undefined if the target is deallocated other than through the
pointer
(16.4.2.1.3).
and
In this standard, "shall" is to be interpreted as a requirement;
conversely, "shall not" is to be interpreted as a prohibition.
Except where stated otherwise, such requirements and prohibitions
apply to programs rather than processors.
If you modify an INTENT (IN) variable, then you have a nonconforming
program. Now, re-read FX's initial sentence. Given FX's code, a
processor can set 'foo = 0' without evaluating 'd - b'.
--
steve
.
- References:
- Optimisation and INTENT
- From: FX
- Re: Optimisation and INTENT
- From: glen herrmannsfeldt
- Optimisation and INTENT
- Prev by Date: Re: Optimisation and INTENT
- Next by Date: Re: An array of arbitrary dimensions made from [0,1]?
- Previous by thread: Re: Optimisation and INTENT
- Next by thread: Re: Optimisation and INTENT
- Index(es):
Relevant Pages
|