Solved! Is it possible to change the value of a constant during compile time?

Just starting out? Need help? Post your questions and find answers here.
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Solved! Is it possible to change the value of a constant during compile time?

Post by SMaag »

For controlling the compile process by code I'm searching for a Methode to change the value of constants!
I'm able to create the constant once. But I can't change the value!
Do anyone of you know a trick how to change the value of a constant.

Code: Select all

Macro macHashTag
  #  
EndMacro


Macro SetConstant(ConstantName, Value)
  CompilerIf Defined(ConstantName, #PB_Constant)
    ; redefine constant with new value???
     
  CompilerElse  ; Constant not defined   
    macHashTag#ConstantName = Value     
  CompilerEndIf 
EndMacro
  
SetConstant(MyConstant, 2)
SetConstant(MyConstant, 3)

Debug #MyConstant
What I want to do with it is:
Switching On/Off a Macro what does a PointerException Check!

if have such Macros what are controlling the PointerExceptionCheck
It can be switched On/Off by PbFwCfg_Module_CheckPointerException or global Off by PbFwCfg_Global_CheckPointerException

The PbFwCfg_Module_CheckPointerException I have to change between #False and #True some times during the compile time.

Code: Select all

 Macro mac_CheckPointer2(ptr1, ptr2, ProcRet=0)
    CompilerIf #PbFwCfg_Module_CheckPointerException And PbFw::#PbFwCfg_Global_CheckPointerException
      If (Not ptr1) Or (Not ptr2)
        DBG::Exception(#PB_Compiler_Module, #PB_Compiler_Procedure, DBG::#PbFw_DBG_Err_PointerIsNull) 
        ProcedureReturn ProcRet
      EndIf 
    CompilerEndIf
  EndMacro
Last edited by SMaag on Tue Jul 30, 2024 9:13 am, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Is it possible to change the value of a constant during compile time?

Post by idle »

you can undefine the macro and make it empty then redefine it but it's compile time only

Code: Select all

Macro foo(x) 
    Debug "on" + Str(x)  
 EndMacro  
 
foo(123) 

UndefineMacro Foo 
Macro foo(x) 
EndMacro 

foo(234) 

UndefineMacro Foo 
 Macro foo(x) 
   Debug "on" + Str(x)  
EndMacro  

foo(345)

BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Is it possible to change the value of a constant during compile time?

Post by BarryG »

SMaag wrote: Mon Jul 29, 2024 9:13 pmI'm able to create the constant once. But I can't change the value!
That's the idea. "Constant" literally means never-changing, so you can't change it. You want a variable, which can be changed.
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Is it possible to change the value of a constant during compile time?

Post by Kiffi »

BarryG wrote: Tue Jul 30, 2024 8:29 amThat's the idea. "Constant" literally means never-changing, so you can't change it. You want a variable, which can be changed.
+1
Hygge
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Solved!

Post by SMaag »

I think I solved it!

1. A part of my idea was totaly nonsens, because if the Procedure is compiled, it i not possible to change.
With that 80% of the Constant problem disappeared!

2. For 20% rest, I define a local constant in the Module what has the same name in all Modules.
Post Reply