Bug or not? Boolean warning. Can you help me make sure it is? [SOLVED]

General FreeBASIC programming questions.
xlucas
Posts: 287
Joined: May 09, 2014 21:19
Location: Argentina

Bug or not? Boolean warning. Can you help me make sure it is? [SOLVED]

Postby xlucas » Sep 17, 2017 0:57

It seems FreeBasic is issuing a warning about boolean comparisons when combined logically with another, non-boolean, comparison, even though there clearly isn't a problem. But maybe I'm seeing it wrong. When I try to do something like this:

Code: Select all

Dim b As Boolean, n As Short

If b And n = 5 Then
    'Some statements
End If


I get a warning that reads: "Mixing operand data types may have undefined results"

OK, then I think, maybe it's associating b with n, trying to solve the And before the =, but then it should be an error, not a warning. The program runs fine, despite the warning. So I try to make things clearer like this:

Code: Select all

If b = True And n = 5 Then


Same thing. I try parentheses.... I try AndAlso.... I try changing the order.... In the end, the only solution is to create an If block inside another If block. I have just installed FreeBasic from the site. Take a look at these tests:

Code: Select all

Dim p As Boolean, c As Short

If p And c = 1 Then Print "Hello"
If p = True And c = 1 Then Print "Hello"
If p AndAlso c = 1 Then Print "Hello"
If p = True AndAlso c = 1 Then Print "Hello"
If (c = 1) And p Then Print "Hello"
If c = 1 AndAlso p = True Then Print "Hello"
If (c = 1) AndAlso (p = True) Then Print "Hello"
GetKey


All issue the warning
Last edited by xlucas on Sep 25, 2017 18:56, edited 1 time in total.
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Bug or not? Boolean warning. Can you help me make sure it is?

Postby sancho2 » Sep 17, 2017 1:36

Try:

Code: Select all

If b = True And cbool(n = 5) Then

This is known and it is talked about in this forum. I will see if I can find the thread and report back.

Found it
FXM says:
Most of time, the operator "=" (Equal) returns an Integer presently.
(exception: a boolean is returned only if the compared expressions are both booleans)
fxm
Posts: 9938
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bug or not? Boolean warning. Can you help me make sure it is?

Postby fxm » Sep 17, 2017 5:42

sancho2 wrote:Found it
FXM says:
Most of time, the operator "=" (Equal) returns an Integer presently.
(exception: a boolean is returned only if the compared expressions are both booleans)

Yes, but the problem is now fixed in the rev 1.06.0 (changelog.txt):
Version 1.06.0
.....
[fixed]
.....
- #797: False-positive warnings when mixing booleans with comparisons in logic operations
.....

But '(n = 5)' always returns an Integer!
See Operator = (Equal)
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Bug or not? Boolean warning. Can you help me make sure it is?

Postby sancho2 » Sep 17, 2017 6:24

1.06 is not yet released though. Is that right?
fxm
Posts: 9938
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bug or not? Boolean warning. Can you help me make sure it is?

Postby fxm » Sep 17, 2017 6:51

Yes, but a current version compiled daily (with manual) is available at http://users.freebasic-portal.de/stw/builds/
Haubitze
Posts: 37
Joined: May 20, 2016 8:42

Re: Bug or not? Boolean warning. Can you help me make sure it is?

Postby Haubitze » Sep 17, 2017 17:49

i think this will work without any problems.

Code: Select all

if ( b = TRUE ) and ( n = 5 ) then
...
endif


salute
xlucas
Posts: 287
Joined: May 09, 2014 21:19
Location: Argentina

Re: Bug or not? Boolean warning. Can you help me make sure it is? [SOLVED]

Postby xlucas » Sep 25, 2017 18:55

Thanks, guys. Yeah, it makes sense that because of how things were in QB and also in FB before Boolean came up, truth in expressions is finally evaluated as an Integer. I like understanding why this happens, not just how to fix it, so thanks again. So if I later want to update FB, which is already installed in my GNU/Linux computer, do I just download the new version and proceed with a normal install? Will it overwrite the old compiler and continue to compile normally?

Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests