Page 1 of 1

seems like a bug MacroExpandedCount

Posted: Wed May 08, 2024 3:13 am
by jassing
helpfile wrote:MacroExpandedCount allows to get the expanded count (number of time the macro has been expanded/called). It can be useful to generate unique identifiers in the same macro for every expansion (like label, procedure name etc.).
(English: "number of times the macro...")

Code: Select all

Macro fry
  Debug MacroExpandedCount
EndMacro

; this will always be 1
For z = 1 To 10
  fry 
Next

; this will count 2,3,4
fry
fry
fry
Doesn't matter loop style (for/while/repeat), so does this loop format

Code: Select all

Macro fry
  Debug MacroExpandedCount
EndMacro

x = 0
more:
fry
x+1
If x < 10 : Goto more : EndIf

Re: seems like a bug MacroExpandedCount

Posted: Wed May 08, 2024 3:18 am
by jacdelad
MacroExpandedCounts returns the number of times the macro is replaced in the source. This has nothing to do with how much the piece of code is executed.

Re: seems like a bug MacroExpandedCount

Posted: Wed May 08, 2024 3:28 am
by Little John
jassing wrote: Wed May 08, 2024 3:13 am

Code: Select all

Macro fry
  Debug MacroExpandedCount
EndMacro

; this will always be 1
For z = 1 To 10
  fry 
Next

; this will count 2,3,4
fry
fry
fry
That's correct, because macro expansion happens at compile time, while the for/next loop is executed at runtime.

Re: seems like a bug MacroExpandedCount

Posted: Sat May 11, 2024 1:12 am
by jassing
Little John wrote: Wed May 08, 2024 3:28 am That's correct, because macro expansion happens at compile time, while the for/next loop is executed at runtime.
In this case, the documentation needs to be changed.

Re: seems like a bug MacroExpandedCount

Posted: Sat May 11, 2024 2:20 am
by Demivec
jassing wrote: Sat May 11, 2024 1:12 am
Little John wrote: Wed May 08, 2024 3:28 am That's correct, because macro expansion happens at compile time, while the for/next loop is executed at runtime.
In this case, the documentation needs to be changed.

How would you change it? It already seems to be clear with this preface in the section on macros:
Macros are a very powerful feature, mainly useful for advanced programmers. A macro is a placeholder for some code (one keyword, one line or even many lines), which will be directly inserted in the source code at the place where a macro is used.
Source code only exists at compile time.

[no bug] Re: seems like a bug MacroExpandedCount

Posted: Sat May 11, 2024 8:24 am
by juergenkulow
--preprocess:

Code: Select all

Macro fry
  Debug MacroExpandedCount
EndMacro
x = 0
more:
Debug 1
x+1
If x < 10 :
 Goto more :
 EndIf
; 1
; 1
; 1
; 1
; 1
; 1
; 1
; 1
; 1
; 1