Page 1 of 1

MacroExpandedCount question

Posted: Fri Mar 17, 2017 5:54 pm
by lule
Hello,
I've got problem with MacroExpandedCount function

Code: Select all

Macro _hGadget
	MacroExpandedCount
EndMacro

;Example 1
Debug "Example1"
Global z1 = _hGadget
Global z2 = _hGadget
Global z3 = _hGadget
Global z4 = _hGadget

Debug z1
Debug z2
Debug z3
Debug z4

;Example 2
Debug "Example2"
Global Dim az.l(4), i
For i = 0 To 3
	az(i) = _hGadget ;<- HERE ERROR AFTER THE FIRST LOOP
Next

For i = 0 To 3
	Debug az(i)
Next
Result :

Example1
1
2
3
4
Example2
5
5
5
5

In case of Array (Example 2) the macro seems not running after the first loop?
Is it a bug or i am doing something wrong?

Re: MacroExpandedCount question

Posted: Fri Mar 17, 2017 6:13 pm
by Thunder93
When using in loops. It'll only record the initial usage but not keep counting. The way Macro's works.

For instance have a look at the following;

Code: Select all

Macro _hGadget
  MacroExpandedCount
EndMacro

For ii = 0 To 5
  Debug _hGadget
Next : Debug ""

For ii = 0 To 5
  Debug _hGadget
Next

Re: MacroExpandedCount question

Posted: Fri Mar 17, 2017 6:14 pm
by spikey
You're doing something wrong - you can't use MacroExpandedCount in the way you are in your second example, or at least you can't use it to get the result you were expecting anyway.

The MacroExpandedCount is handled by the macro preprocessor when the code is compiled, not at runtime. The result is correct because the macro is only expanded once in that loop in the compilation process. The loop executes more than once at runtime but this is irrelevant.

Re: MacroExpandedCount question

Posted: Fri Mar 17, 2017 8:23 pm
by lule
Thanks for answers.

I forgot it on every macro's use.
I have replaced macro by a procedure with static var.