Author Topic: Macro parameter question  (Read 98 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 697
    • PluriBASIC
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

  • Admin Support Member
  • *****
  • Posts: 4461
    • Oxygen Basic
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

  • Hero Member
  • *****
  • Posts: 697
    • PluriBASIC
Re: Macro parameter question
« Reply #2 on: February 09, 2021, 09:51:25 am »

 I see. Does Typecodeof(null) return 0?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4461
    • Oxygen Basic
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

  • Hero Member
  • *****
  • Posts: 697
    • PluriBASIC
Re: Macro parameter question
« Reply #4 on: February 09, 2021, 11:05:11 am »
 Thanks Charles, i will implement it. :)