seems like a bug MacroExpandedCount

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

seems like a bug MacroExpandedCount

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: seems like a bug MacroExpandedCount

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: seems like a bug MacroExpandedCount

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: seems like a bug MacroExpandedCount

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: seems like a bug MacroExpandedCount

Post 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.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

[no bug] Re: seems like a bug MacroExpandedCount

Post 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
Post Reply