Bool() with constants => constant

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Bool() with constants => constant

Post by CSHW89 »

Can the function "Bool" with constants be evaluated at compile time?

Work with PB 5.00:

Code: Select all

Macro enum2pow(_const_)
  _const_ = ((#PB_Compiler_EnumerationValue=1 And 1) + (#PB_Compiler_EnumerationValue>1 And 1) * ((#PB_Compiler_EnumerationValue-1)<<1))
EndMacro

Enumeration 1
  enum2pow(#A1) ;1
  enum2pow(#A2) ;2
  enum2pow(#A3) ;4
  enum2pow(#A4) ;8
EndEnumeration
... but this don't with PB 5.10:

Code: Select all

Macro enum2pow(_const_)
  _const_ = (Bool(#PB_Compiler_EnumerationValue=1) + Bool(#PB_Compiler_EnumerationValue>1) * ((#PB_Compiler_EnumerationValue-1)<<1))
EndMacro
lg Kevin
Image Image Image
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Bool() with constants => constant

Post by luis »

Yes, Bool() does not seem to work in that case.

But you don't need to do all that strange stuff to make enumerations emit a Pow2 progression.

See "Can't you just use a macro ?" -> http://www.purebasic.fr/english/viewtop ... 53#p397053

EDIT: As a side effect, that code seems to disable the reply button in the forum.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply