[Implemented] bit-wise enumerations.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

[Implemented] bit-wise enumerations.

Post by jassing »

I frequently use constants for bit-enumeration (1,2,4,8,16,32,64,128 etc) It would be nice if there was an enumeration form that automatically incremented by doubling vs. adding 1.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: bit-wise enumerations.

Post by luis »

Can't you just use a macro ?

Code: Select all

Macro POW2
 (#PB_Compiler_EnumerationValue - 1) << 1
EndMacro

Enumeration 
 #ONE   = 1
 #TWO   = POW2
 #THREE = POW2
 #FOUR  = POW2
 #FIVE  = POW2
 #SIX   = POW2
EndEnumeration

Debug #ONE
Debug #TWO
Debug #THREE
Debug #FOUR
Debug #FIVE
Debug #SIX
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply