Whats the PB equivalent for boolean

Just starting out? Need help? Post your questions and find answers here.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Whats the PB equivalent for boolean

Post 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()
"Daddy, I'll run faster, then it is not so far..."
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Whats the PB equivalent for boolean

Post by DarkDragon »

BOOL is not equal to bool. BOOL is an int. So its 32bit.
bye,
Daniel
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Whats the PB equivalent for boolean

Post by srod »

A BOOL variable could use as little as 1 bit, but SystemParametersInfo_() is clearly writing a 32-bit integer here.
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Whats the PB equivalent for boolean

Post by Trond »

Better use .i for all variables for optimum performance.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Whats the PB equivalent for boolean

Post 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.
"Daddy, I'll run faster, then it is not so far..."
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Whats the PB equivalent for boolean

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Whats the PB equivalent for boolean

Post by netmaestro »

BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Whats the PB equivalent for boolean

Post 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.
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Re: Whats the PB equivalent for boolean

Post 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 ...? :wink:

Cheers,
Lewis
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Whats the PB equivalent for boolean

Post by blueznl »

Well, PureBasic assumes 0 = false, and not-zero is true... as far as I know -1 is not zero, so... :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Whats the PB equivalent for boolean

Post by DarkDragon »

Guys.. the problem is solved. So many other topics could need your help :-P .
bye,
Daniel
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Whats the PB equivalent for boolean

Post by blueznl »

Those other questions are too difficult for me :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Re: Whats the PB equivalent for boolean

Post 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. :wink: Tips: Code and run X = NOT 0, and then code and run Y = NOT -1. :idea:

Cheers,
Lewis
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Whats the PB equivalent for boolean

Post 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. :wink: Tips: Code and run X = NOT 0, and then code and run Y = NOT -1. :idea:
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
User avatar
Lewis
User
User
Posts: 47
Joined: Fri Nov 25, 2005 1:12 pm

Re: Whats the PB equivalent for boolean

Post 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. :wink: Tips: Code and run X = NOT 0, and then code and run Y = NOT -1. :idea:
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).
Post Reply