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