Save way to check for empty Macro parameters

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Save way to check for empty Macro parameters

Post by technicorn »

Right now there is no save way to check if a Macro parameter is empty.
You could use this trick, but the last one will not work, because the compiler
complains about to many characters between ''

Code: Select all

Macro SQCHAR
'
EndMacro

Macro SQTME(x)
SQCHAR#x#SQCHAR
EndMacro

Macro m1(param=)
CompilerIf SQTME(param) <> ''
  Debug param
CompilerElse
  Debug "nothing"
CompilerEndIf
EndMacro

a = 1234
verylongvariable = 1
m1()
m1("Hello")
m1(a)
m1(verylongvariable)
Would be nice to have something like

MacroParameterIsEmpty(param)

Which could return 1 for empty param

Or

MacroParamterLen(param)

Which could return the lenght of the parameter.

Or more general

ExpandedLen(anything)

Which does a normal expansion like already done in macro expansion
and then inserts the constant value for the lenght of the expanded text.

Or use Defined(param) with only one parameter and it gives back 0/1 ?

Of course all those would be compile time functions

Seasons's greetings
Technicorn