Author Topic: Macro parameter question  (Read 717 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Macro parameter question
« on: February 08, 2021, 01:48:15 PM »
 Hello, I would like a macro to generate a certain block of code only if one of the passed parameters is not a literal null. What  can i use to achieve this safely?

 Right now i am using:

Code: [Select]
#if typecodeof(p) <> 0

#endif

 Is this safe? is there a better way? Is it possible?
« Last Edit: February 08, 2021, 03:02:02 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: Macro parameter question
« Reply #1 on: February 09, 2021, 05:04:24 AM »
Hi Brian,

Typecodeof will work for null, literals and variables but not for parameters consisting of expressions and functions.


Brian Alvarez

  • Guest
Re: Macro parameter question
« Reply #2 on: February 09, 2021, 09:51:25 AM »

 I see. Does Typecodeof(null) return 0?

Charles Pegge

  • Guest
Re: Macro parameter question
« Reply #3 on: February 09, 2021, 10:19:54 AM »
Yes, but this might be a better option. I am tweaking the match metafunction to support expressions as well as single words:

Code: [Select]
macro mf(p)
#if not match((p),(null))
   print "not null"
#else
   print "null"
#endif
end macro

mf null
mf 0
mf 1/4


Brian Alvarez

  • Guest
Re: Macro parameter question
« Reply #4 on: February 09, 2021, 11:05:11 AM »
 Thanks Charles, i will implement it. :)