Page 1 of 2
Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 11:56 am
by dige
I'm beginning to love the Purifier! Now I've found a memoryleak
that I have since ages.
This brings me to the question about: which is the correct type
of data equivalent for boolean?
BOOL can be True or False, is'nt it? Sound like it needs only one Byte
or less...
So is the right PB equivalent for boolean Byte.b?
There is a fixed code below, to check if a screensave is activ
or not. It works also with Status.b as Byte. But the Purifier
recognize a corrupt stack after calling it.
Code: Select all
Procedure.L CheckIsScreenSaverActiv()
Protected Status.L, success.b, Bool.b
; Win32hlp: SPI_GETSCREENSAVEACTIVE Determines whether screen saving is enabled.
; The parameter must point To BOOL variable that receives TRUE If enabled,
; or FALSE otherwise.
SystemParametersInfo_( #SPI_GETSCREENSAVEACTIVE, #Null, @Status, #Null )
;SystemParametersInfo_( #SPI_GETSCREENSAVEACTIVE, #Null, @Bool, #Null )
ProcedureReturn Status
EndProcedure
Debug CheckIsScreenSaverActiv()
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 12:08 pm
by DarkDragon
BOOL is not equal to bool. BOOL is an int. So its 32bit.
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 12:08 pm
by srod
A BOOL variable could use as little as 1 bit, but SystemParametersInfo_() is clearly writing a 32-bit integer here.
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 1:36 pm
by Trond
Better use .i for all variables for optimum performance.
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 2:01 pm
by dige
@Trond: If you use api calls, it's better to use .l if necessary.
Because that 'fix' the data type to 4 Byte Integer.
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 4:47 pm
by blueznl
Re: Whats the PB equivalent for boolean
Posted: Wed Oct 13, 2010 10:07 pm
by netmaestro
Re: Whats the PB equivalent for boolean
Posted: Thu Oct 14, 2010 6:27 am
by ts-soft
dige wrote:@Trond: If you use api calls, it's better to use .l if necessary.
Because that 'fix' the data type to 4 Byte Integer.
Only in a structure, here is integer the best choice.
Re: Whats the PB equivalent for boolean
Posted: Thu Oct 14, 2010 12:33 pm
by Lewis
I believe the preferred way to implement boolean is that
0 = FALSE
and NOT FALSE = -1
Since NOT FALSE = TRUE then TRUE = -1.
It follows that NOT TRUE = 0.
Unfortunately there are not many languages that implement boolean that way.
Food for thought ...?
Cheers,
Lewis
Re: Whats the PB equivalent for boolean
Posted: Thu Oct 14, 2010 4:02 pm
by blueznl
Well, PureBasic assumes 0 = false, and not-zero is true... as far as I know -1 is not zero, so...

Re: Whats the PB equivalent for boolean
Posted: Thu Oct 14, 2010 5:11 pm
by DarkDragon
Guys.. the problem is solved. So many other topics could need your help

.
Re: Whats the PB equivalent for boolean
Posted: Thu Oct 14, 2010 6:13 pm
by blueznl
Those other questions are too difficult for me

Re: Whats the PB equivalent for boolean
Posted: Sun Oct 24, 2010 11:52 am
by Lewis
blueznl wrote:Well, PureBasic assumes 0 = false, and not-zero is true... as far as I know -1 is not zero, so...

:roll: Very observant of you, blueznl!

However, the value not-zero is impossible to use
directly in calculations, unlike a TRUE value of -1, which in certain circumstances can also improve code readability.

Tips: Code and run X = NOT 0, and then code and run Y = NOT -1.
Cheers,
Lewis
Re: Whats the PB equivalent for boolean
Posted: Sun Oct 24, 2010 2:45 pm
by Demivec
Lewis wrote:blueznl wrote:Well, PureBasic assumes 0 = false, and not-zero is true... as far as I know -1 is not zero, so...

:roll: Very observant of you, blueznl!

However, the value not-zero is impossible to use
directly in calculations, unlike a TRUE value of -1, which in certain circumstances can also improve code readability.

Tips: Code and run X = NOT 0, and then code and run Y = NOT -1.

There is more than one way to flip a boolean value.
Code: Select all
;using bitwise NOT
x = 0
x = ~ x
Debug x
x = ~ x
Debug x
Debug "----"
;using bitwise XOR
x = 0
x ! 1
Debug x
x ! 1
Debug x
Re: Whats the PB equivalent for boolean
Posted: Sat Oct 30, 2010 12:19 pm
by Lewis
Demivec wrote:Lewis wrote:blueznl wrote:Well, PureBasic assumes 0 = false, and not-zero is true... as far as I know -1 is not zero, so...

:roll: Very observant of you, blueznl!

However, the value not-zero is impossible to use
directly in calculations, unlike a TRUE value of -1, which in certain circumstances can also improve code readability.

Tips: Code and run X = NOT 0, and then code and run Y = NOT -1.

There is more than one way to flip a boolean value.
Code: Select all
;using bitwise NOT
x = 0
x = ~ x
Debug x
x = ~ x
Debug x
Debug "----"
;using bitwise XOR
x = 0
x ! 1
Debug x
x ! 1
Debug x
Sure, although this doesn't contribute much to the TRUE/FALSE thread (for what that
academic conversation is worth).