Re: Optimisation and INTENT



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

.



Relevant Pages

  • Re: The annotated annotated annotated C standard
    ... If you wanted to discuss my review of the book, ... not only is this the obsolete ANSI standard rather than the ISO ... student's guide to C programming on the x86 family". ...     Many of these comments might appear to be relatively trivial. ...
    (comp.programming)
  • Re: The annotated annotated annotated C standard
    ... The job of a Standard is to be precise and unambiguous. ...     Many of these comments might appear to be relatively trivial. ... competent maintenance programmer would do is rewrite the appropriate code. ... It's a *criticism* of his writing. ...
    (comp.programming)
  • Re: Programming in standard c
    ... programming exclusively in standard C is completely impossible even ...    to use ftell/fseek to determine the file size. ... in vendor libraries or libraries related to other standards like ... language itself might be a good thing, if you can get all of the ...
    (comp.lang.c)
  • Re: Dana Tweedy: Registered offender?
    ...    Even though I knew he was just being a jerk, ... evidence to support something, ... me to the standard of truth, the same one I use, and I'll not object. ...
    (talk.origins)
  • Re: Language lawyers: Was: Re: Paging the gfortran (64-bit Linux, medium memory model) mavens
    ... language lawyers -- is this line of code legal standard Fortran? ... F77 does not allow zero-length strings. ... distributions (or the standard CMS distributions, ...   write'' ...
    (comp.lang.fortran)