[Implemented] EnumerationBinary starting from 0

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

[Implemented] EnumerationBinary starting from 0

Post by Michael Vogel »

Code: Select all

EnumerationBinary ;#Null
	;#STPF_NONE=0
	#STPF_USEAPPTHUMBNAILALWAYS
	#STPF_USEAPPTHUMBNAILWHENACTIVE
	#STPF_USEAPPPEEKALWAYS
	#STPF_USEAPPPEEKWHENACTIVE
EndEnumeration

Debug #STPF_USEAPPPEEKWHENACTIVE
I'd like to be able to start enumerate binary flags starting from 0.
Removing one of the commented parts in the code example above shows that this can't be done.


My Workaround:

Code: Select all

Macro BinaryEnumeration
	((#PB_Compiler_EnumerationValue-1)<<1+((#PB_Compiler_EnumerationValue-2)&$8000000+(~-#PB_Compiler_EnumerationValue)&$8000000)>>27)
EndMacro

Enumeration #Null
	#STPF_NONE						=BinaryEnumeration
	#STPF_USEAPPTHUMBNAILALWAYS		=BinaryEnumeration
	#STPF_USEAPPTHUMBNAILWHENACTIVE =BinaryEnumeration
	#STPF_USEAPPPEEKALWAYS			=BinaryEnumeration
	#STPF_USEAPPPEEKWHENACTIVE		=BinaryEnumeration
EndEnumeration

Debug #STPF_NONE
Debug #STPF_USEAPPPEEKWHENACTIVE
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: EnumerationBinary starting from 0

Post by wilbert »

Code: Select all

EnumerationBinary
   #STPF_NONE = 0
   #STPF_USEAPPTHUMBNAILALWAYS = 1
   #STPF_USEAPPTHUMBNAILWHENACTIVE
   #STPF_USEAPPPEEKALWAYS
   #STPF_USEAPPPEEKWHENACTIVE
EndEnumeration

Debug #STPF_USEAPPPEEKWHENACTIVE
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: EnumerationBinary starting from 0

Post by Michael Vogel »

wilbert wrote:

Code: Select all

EnumerationBinary
   #STPF_NONE = 0
   #STPF_USEAPPTHUMBNAILALWAYS = 1
   #STPF_USEAPPTHUMBNAILWHENACTIVE
   #STPF_USEAPPPEEKALWAYS
   #STPF_USEAPPPEEKWHENACTIVE
EndEnumeration

Debug #STPF_USEAPPPEEKWHENACTIVE
Nice try, Wilbert :P

I still prefer a fool proof handling, so the next value after 0 should be 1 - this could save you some time for trouble shooting.
Post Reply