PGI wierdness with .EQV.
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
PGI wierdness with .EQV.         


Author: Carlie J. Coats
Date: Jun 19, 2008 05:11

I am the primary maintainer of an open-source environmental-data
I/O library, and one of my (historically very astute) users reports
that the program below does not behave correctly when compiled with
PGI F90 (of which I don't have a copy). Either replacing the
IF-clause by the logically equivalent "IF ( LVAR ) THEN" or using
an alternate compiler (g95, ifort, sunf95) causes the program to behave
as expected.

What the ??!!? How does a bug this blatant get through testing?

Carlie Coats
Baron Advanced Meteorological Systems

----------------------------------------------------------
PROGRAM TEST_ENVYN

LOGICAL :: ENVYN, LVAR
INTEGER :: ISTAT

LVAR = ENVYN('LVAR','logical variable',.TRUE.,ISTAT)
Show full article (0.88Kb)
67 Comments
Re: PGI wierdness with .EQV.         


Author: glen herrmannsfeldt
Date: Jun 19, 2008 07:11

Carlie J. Coats wrote:
> I am the primary maintainer of an open-source environmental-data
> I/O library, and one of my (historically very astute) users reports
> that the program below does not behave correctly when compiled with
> PGI F90 (of which I don't have a copy). Either replacing the
> IF-clause by the logically equivalent "IF ( LVAR ) THEN" or using
> an alternate compiler (g95, ifort, sunf95) causes the program to behave
> as expected.
> What the ??!!? How does a bug this blatant get through testing?

What is the actual bit value of LVAR? If it is not the
same as .TRUE. or .FALSE. then it might be that it is
non-standard, and fails.

LOGICAL LVAR,ENVYN
INTEGER IVAR
EQUIVALENCE(LVAR,IVAR)
LVAR = ENVYN('LVAR','logical variable',.TRUE.,ISTAT)
WRITE(*,'(Z8)') IVAR
END
Show full article (1.31Kb)
no comments
Re: PGI wierdness with .EQV.         


Author: James Van Buskirk
Date: Jun 19, 2008 09:07

"Carlie J. Coats" jyarborough.com> wrote in message
news:R1s6k.21310$3j2.2568@trnddc03...
> I am the primary maintainer of an open-source environmental-data
> I/O library, and one of my (historically very astute) users reports
> that the program below does not behave correctly when compiled with
> PGI F90 (of which I don't have a copy). Either replacing the
> IF-clause by the logically equivalent "IF ( LVAR ) THEN" or using
> an alternate compiler (g95, ifort, sunf95) causes the program to behave
> as expected.
> What the ??!!? How does a bug this blatant get through testing?
> PROGRAM TEST_ENVYN
> LOGICAL :: ENVYN, LVAR
> INTEGER :: ISTAT
> LVAR = ENVYN('LVAR','logical variable',.TRUE.,ISTAT)
> IF ( .TRUE. .EQV. LVAR ) THEN
> PRINT*, 'LVAR = TRUE'
> ELSE
> PRINT*, 'LVAR = FALSE'
> ENDIF
Show full article (3.49Kb)
no comments
Re: PGI wierdness with .EQV.         


Author: nospam
Date: Jun 19, 2008 10:23

Carlie J. Coats jyarborough.com> wrote:
> that the program below does not behave correctly when compiled with
> PGI F90 (of which I don't have a copy). Either replacing the
> IF-clause by the logically equivalent "IF ( LVAR ) THEN" or using
> an alternate compiler (g95, ifort, sunf95) causes the program to behave
> as expected.
...
> IF ( .TRUE. .EQV. LVAR ) THEN

Well, stylistically, I far prefer the simpler "IF (LVAR)", but that
aside...

1. As Glen and James note, if your LVAR is not a properly defined
logical variable, then all bets are off; that would be a program bug,
not a compiler one, even if the program happened to work with many other
compilers. That's the kind of thing that happens with nonstandard code.
Show full article (2.39Kb)
no comments
Re: PGI wierdness with .EQV.         


Author: glen herrmannsfeldt
Date: Jun 19, 2008 12:14

James Van Buskirk wrote:
(snip)
> If they then mapped .AND. to && and .OR. to || and .NOT. to !
> and .NEQV. to ^^ and .EQV. to ^^!, everything would at least
> be consistent and truth tables would be valid. Unfortunately
> C has no ^^ operator and it is also found useful to use the
> logical operators to achieve masking operations as &, |, ~, ^,
> and ^~ .

I know DEC compilers were allowing integers as operands
of logical operators generating bitwise logical results
in the Fortran 66 days. They would also convert between
INTEGER and LOGICAL transferring the bits over. As well
as I remember, they only tested one bit, though I am not
sure which one.

The bitwise logical functions seem a better way to me.

It would be nice if C had the ^^ and ^^= operators.

-- glen
no comments
Re: PGI wierdness with .EQV.         


Author: James Giles
Date: Jun 19, 2008 12:03

glen herrmannsfeldt wrote:
...
> It would be nice if C had the ^^ and ^^= operators.

Well, a^^b would be the same as !a ^ !b. So, a^^=b would
be a = !a ^ !b. Of course if the thing on the left of the assignment
were a lvalue whose generaton involved side-effects, you would
have to introduce a temporary pointer variable. It's C after all.

--
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

"Simplicity is prerequisite for reliability" -- E. W. Dijkstra
no comments
Re: PGI wierdness with .EQV.         


Author: Greg Lindahl
Date: Jun 19, 2008 13:22

In article comcast.com>,
James Van Buskirk comcast.net> wrote:
>This happens because Fortran compilers tend to get written in C.
>Thus, the compiler programmers don't have a lick of Fortran sense
>and think that it's reasonable for the internal representation of
>LOGICAL variables to be such that transfer(0,.TRUE.) is .FALSE.
>and anything else is .TRUE. .

I don't read your postings very often, and this statement is a good
example of why. Every compiler team that I'm familiar with has some
real Fortran guys on it, and several of them read this newsgroup.

Just because you think representing LOGICALs has an obvious answer
doesn't mean that they agree with you, especially when you're
arguing against historical choices, and in a rude fashion.

-- greg
no comments
Re: PGI wierdness with .EQV.         


Author: Steve Lionel
Date: Jun 19, 2008 14:15

On Thu, 19 Jun 2008 12:11:29 GMT, "Carlie J. Coats" jyarborough.com>
wrote:
>I am the primary maintainer of an open-source environmental-data
>I/O library, and one of my (historically very astute) users reports
>that the program below does not behave correctly when compiled with
>PGI F90 (of which I don't have a copy). Either replacing the
>IF-clause by the logically equivalent "IF ( LVAR ) THEN" or using
>an alternate compiler (g95, ifort, sunf95) causes the program to behave
>as expected.

I suppose that if LVAR's value was not the canonical .TRUE. or .FALSE. value
(that is, it got defined in some manner other than the result of a LOGICAL
assignment or expression) then the standard perhaps is silent on the behavior,
but... Since using IF (LVAR) worked, something very odd is happening and an
inquiry to PGI is in order. Nevertheless, I agree with others that IF(LVAR)
is the preferred syntax.

Some years ago I wrote an article on common misimpressions regarding the
LOGICAL type and its uses, with a special note regarding .EQV.. You can find
it at http://tinyurl.com/4aqgtn
Show full article (1.46Kb)
no comments
Re: PGI wierdness with .EQV.         


Author: James Van Buskirk
Date: Jun 19, 2008 18:35

"Richard Maine" wrote in message
news:1iis15t.g71d55uykqlsN%%nospam@see.signature...
> If you happen to have a both a C99 (I think it is new to C99, but I'm
> not 100%% sure of that) compiler with the _Bool type and an F2003
> compiler that supports that C compiler as a companion processor, then
> you can use a Fortran logical to interoperate with a C _Bool.

Um, no. If we look at n1124.pdf, section 6.3.1.2:

"When any scalar value is converted to _Bool, the result is 0 if the
value compares equal to 0; otherwise, the result is 1."
Show full article (1.69Kb)
no comments
Re: PGI wierdness with .EQV.         


Author: nospam
Date: Jun 19, 2008 20:26

James Van Buskirk comcast.net> wrote:
> Responses received have served to confirm my assertion that you
> can't talk sense to the vendors on the issue of adhering to the
> truth tables given in the standard document.

I vehemently disagree with you on this (which is to say that I agree
with the vendors). There is not a single vendor that fails to "adhere to
the truth tables given in the standard document."

Those truth tables, like every other operation definition in the
standard, apply only to operand values that are "defined" in the precise
sense of the standard. If you have done any form of bit twiddling on the
logical values, then the standard clearly and explicitly says that the
values are not defined.

Once you reference an undefined value, all bets are off. That is the
program violating the standard, not the compiler. The compiler is under
no obligation to detect such problems or to give any consistent results.
Show full article (1.68Kb)
no comments
1 2 3 4 5 6 7