For Programmers: Free Programming Magazines  


Home > Archive > Fortran > June 2004 > Re: Function PRESENT and logical combinations









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Function PRESENT and logical combinations
James Giles

2004-06-25, 7:43 pm

Toon Moene wrote:
> James Giles wrote:
>
>
> 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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com