Page 1 of 1

Bool() with constants => constant

Posted: Sat Mar 02, 2013 12:11 am
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

Re: Bool() with constants => constant

Posted: Sat Mar 02, 2013 12:34 am
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.