Reminds me of a situation I had some years ago while writing a VBA program that 
used a class (for FTP, I think) that had been written in some flavor of C.  I 
was testing a supposedly Boolean return code and getting unexpected results.  I 
tried several ways, and eventually proved to myself that the return code was 
both True and False.  That is:

  Result = Function(Argument)
  If Result Then MsgBox "True"
  If Not Result Then MsgBox "False"

...displayed ~both~ messages.  Maybe some of you already know what was 
happening here, but I had to examine the returned value in hex to catch on.  
VBA uses -1 (1111 1111b) for True and 0 (0000 0000b) for False, but evaluates 0 
as False and any non-zero number as True.  The Not operand uses two's 
complement to negate.  But C, I gather, uses 0 for False and 1 for True.  So in 
this case I was getting a 1 back from the function (0000 0001b), which VBA 
evaluated as True - and when I said "Not Result", it negated 1 into -2 (1111 
1110b) and evaluated that as True also.

Easy to write around once I understood what  was going on, but it did confuse 
me for a while.

---
Bob Bridges, robhbrid...@gmail.com, cell 336 382-7313

/* Every wise workman takes his tools away from the work from time to time that 
they may be ground and sharpened; so does the only-wise Jehovah take his 
ministers oftentimes away into darkness and loneliness and trouble, that he may 
sharpen and prepare them for harder work in his service.  -Robert Murray 
M'Cheyne (1813-1843) */

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Bernd Oppolzer
Sent: Friday, June 5, 2020 19:35

This triggered me once more, sorry :-)

I recall that we once did a larger project, checking all the PL/1 sources
at a customer of mine, looking for errors in program logic, using a tool
that I wrote (sort of a light weight, yet powerful, PL/1 parser).

The parser threw errors (observations) on about ten percent of the 
source codes.

One program had this coding:

IF 9 < ZZ < 20 THEN DO;

no error from the compiler, no warning :-)

the condition turned out to be always true, because

(9 < ZZ) < 20

the left part is evaluated and gives a binary result (BIT(1) in PL/1 
speech);
this is converted to decimal, and no matter what the value of ZZ is,
the BIT(1) is always lower than 20 (be it '0'B or '1'B).

This was of course not what the author intended; this was at an insurance
company where most of the programmers had a math background, so this
kind of expression was natural to them. The compiler didn't complain.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to