Hi,
if a macro is defined inside of a procedure, it should be valid therein only, without the need to use UndefineMacro before the next definition.
Greatings
Uwe
Macros defined inside procedures should be valid therin only
Macros defined inside procedures should be valid therin only
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Re: Macros defined inside procedures should be valid therin
Hi uwekel. Unlike the code compilation process, PureBasic's macro system simply scans the source code top down, and expands the macro placeholders wherever they're found. Only parameter-based macros are validated, and the rest is left to the compiler. So, in its current form, it would not be able to recognise code scopes. To do so would require a revamp of the current macro system. IMHO.uwekel wrote:if a macro is defined inside of a procedure, it should be valid therein only...
What you're suggesting can already be done with FASM's macro system, and can be utilised with inline Assembly. Here's an example:
Code: Select all
; tested with PureBasic v5.31 x64 on Windows 8.1
msg.s
;*** global FASM macro *****************
!macro globalMacro
!{
MessageRequester("Global Macro:", msg)
!}
;***************************************
Procedure myProcedure(msg.s)
;*** local FASM macro *****************
!macro localMacro
!{
MessageRequester("Local Macro:", msg)
!}
;**************************************
!localMacro ;calls local macro
!globalMacro ;calls global macro
EndProcedure
msg = "...being called from procedure"
myProcedure(msg)
msg = "...being called from main program"
!globalMacro ;calls global macro
;!localMacro ;local procedure macros cannot be used
Just some thoughts.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Macros defined inside procedures should be valid therin
Just came across this behavior as I needed a Macro within a Procedure to save typing.
Please add a reference to the manual...
Please add a reference to the manual...
Add to Help wrote:Macros can be defined within Procedures and it is recommended to 'Undefine Macro' prior to ProcedureReturn.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Macros defined inside procedures should be valid therin
skywalk, thanks for pointing this out. I wasn't aware of it either and really think it should be noted in the help file.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!