PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: Bumblebee on November 23, 2023, 10:19:34 AM

Title: Question about warning 38
Post by: Bumblebee on November 23, 2023, 10:19:34 AM
WinFBE_VD_MAIN.bas(382) warning 38(1): Suspicious logic operation, mixed boolean and non-boolean operands
 :o
What is the reasoning behind this warning?

The code in question is:
if left(a,5) = "name=" and len(a) > 5 and nf = false then print #5,c;tab(30);mid(a,6)
Title: Re: Question about warning 38
Post by: Paul Squires on November 23, 2023, 11:24:45 AM
I remember getting warnings like this all the time in a version of FreeBasic many moons ago. I thought that they had eliminated or relaxed that warning in recent versions (?). What version of the compiler are you using?

The warning occurs because you are mixing boolean operations (nf = false) with non-boolean (the first part of your statement), and wanting the entire result of the statement to evaluate to an overall true/false boolean result.

You'd have to do something like this to quiet the compiler.

if cbool(left(a,5) = "name=") and cbool(len(a) > 5) and nf = false then print #5,c;tab(30);mid(a,6)

As an aside, I'd also change the "and" to "andalso" because andalso works better with boolean evaluation.


Title: Re: Question about warning 38
Post by: Bumblebee on November 23, 2023, 02:11:08 PM
I'm using FreeBASIC-1.07.2-gcc-5.2\fbc64.exe

I rearranged the terms and for some reason this quietens the warning:
if left(a,5) = "name=" and nf = false and len(a) > 5 then print #5,c;tab(30);mid(a,6)
Andalso is new to me, I'm having trouble understanding it.
Title: Re: Question about warning 38
Post by: Paul Squires on November 23, 2023, 02:33:24 PM
Looks like you are 4 versions behind the newest FB version:
https://sourceforge.net/projects/fbc/files/FreeBASIC-1.10.0/Binaries-Windows/
Title: Re: Question about warning 38
Post by: Bumblebee on November 23, 2023, 02:41:10 PM
Can you confirm that the issue (if it should be called that) is fixed in the latest version?

Edit:
Preliminary testing indicates the warning is still there.
Title: Re: Question about warning 38
Post by: Paul Squires on November 24, 2023, 06:59:19 AM
Quote from: Bumblebee on November 23, 2023, 02:41:10 PMCan you confirm that the issue (if it should be called that) is fixed in the latest version?

Looks like the latest version also generates the same warning. The posts at this link https://www.freebasic.net/forum/viewtopic.php?t=32300 tend to imply that the behaviour is necessary to ensure "backwards compatibility" with older FB versions.

I guess that I must have "misremembered" that the warning had been taken care of in newer versions.

Looks like you'll have to use the cbool approach.
Title: Re: Question about warning 38
Post by: Bumblebee on November 24, 2023, 12:15:52 PM
I'm using this version without a warning being raised:
if left(a,5) = "name=" and nf = false and len(a) > 5 then print #5,c;tab(30);mid(a,6)
The first expressions are true/false, yes/no outcomes.
The final one involves a range, a set of integers {6,7,8,...}
If this is backward compatible, I've no idea. The executable works as intended :)
Title: Re: Question about warning 38
Post by: José Roca on November 25, 2023, 05:53:50 AM
Have you tried to use 0 instead of false? I use 0 for false and <> 0 for true.
Title: Re: Question about warning 38
Post by: Bumblebee on November 25, 2023, 11:06:51 AM
Quote from: José Roca on November 25, 2023, 05:53:50 AMHave you tried to use 0 instead of false? I use 0 for false and <> 0 for true.
I tried it and there are no warnings no matter how I arrange the expressions.