• Welcome to PlanetSquires Forums.
 

Question about warning 38

Started by Bumblebee, November 23, 2023, 10:19:34 AM

Previous topic - Next topic

Bumblebee

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)
Failed pollinator.

Paul Squires

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.


Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

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.
Failed pollinator.

Paul Squires

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

#4
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.
Failed pollinator.

Paul Squires

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.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

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 :)
Failed pollinator.

José Roca

Have you tried to use 0 instead of false? I use 0 for false and <> 0 for true.

Bumblebee

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.
Failed pollinator.