Re: Function PRESENT and logical combinations

From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 06/18/04


Date: Fri, 18 Jun 2004 21:36:04 GMT

Toon Moene wrote:
> James Giles wrote:
>
>> I think that's a profound misinterpretation of the concept of
>> "as-if". Execution is the ultimate authority on the semantic
>> meaning of the program.
>
> Depends on your definition of "execution" (and what the meaning of "is"
> is - sorry, couldn't resist :-)
>
> Given the following Fortran program:
>
> LOGICAL FUNCTION WHATIF()
> WHATIF = .FALSE.
> END
> PROGRAM PROG
> LOGICAL WHATIF
> IF (WHATIF()) THEN
> PRINT*, 'WHOAH'
> ELSE
> PRINT*, 'YEAH, RIGHT'
> ENDIF
> END
>
> and compiling with g77 -O2 -finline-functions -S, the resulting
> assembler file shows that the compiler completely elided the
>
> IF (WHATIF()) THEN
> PRINT*, 'WHOAH'
> ELSE
> ENDIF
>
> part and only retained the
>
> PRINT*, 'YEAH, RIGHT'
>
> part.
>
> Now, depending on your definition of "execute", this might mean that the
> "processor" didn't "execute" the function.

The compiler clearly determined what the return value
of the function is, and took action based on that infomation.
It accomplished all the semantic consequences of the
function (and the program that referenced it). How is
that not "execution"?

The "processor" consists of the entirety of the implementation:
not just "run-time" behavior. The processing occuring during
"compile-time" can be part of the execution of the code. The
standard makes no such distinctions as "run-time" or "compile-
time" nor can any definition of "execution" depend on such
concepts.

Section 2.3 is pretty explicit, and the behavior you describe
is exactly "as-if" the source were naively executed in the
manner described in that section.

-- 
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."  -- C. A. R. Hoare


Relevant Pages

  • Re: function : question on argument for output
    ... That would deviate from the standard's definition of "execution ... The only reason the compiler is allowed to skip the ... It isn't good language design to say that something is allowed in the ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Pi.
    ... > James Giles wrote: ... >>> can be elided for the convenience of the compiler as opposed to ... All the more reason not to change them *after* you've double-checked ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: cvf/ide - colored keywords
    ... > James Giles wrote: ... >> up syntax coloring. ... The document is on the CD that the compiler was distributed on. ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Obstacles for Tcl/Tk commercial application development ?
    ... this is no problem: the compiler will refuse to ... previous message, it is impossible to check all execution paths, ... kilometers, which is clearly a type error. ...
    (comp.lang.tcl)
  • Re: FORTH: BEGIN as compile-time and no run-time?!?!?!?!? Help
    ... of the compiler for your own purposes. ... For example,] switches to compile mode and [to execute mode. ... execution tokens of its parts. ... whenever there is a 0 on the stack. ...
    (comp.lang.asm.x86)