Archive: validate macro parameters at compile time?


validate macro parameters at compile time?
Is it possible to validate macro parameters at compile time? IOW, is there something like an "!ifequal" command and I just can't find it?

Here's an example showing what I'm looking for given the hypothetical !isequal command:


!macro foo _stmt _var1 _op _var2
!define _uid {__LINE__}
!ifequal _op "=" Continue${_uid}
!ifequal _op "<>" Continue${_uid}
!ifequal _op ">" Continue${_uid}
!ifequal _op "<" Continue${_uid}
!error "3rd param must be be one of: =, <>, <, or >."

Continue${_uid}:

...do work here

!undef _uid {__LINE__}
!macroend

I wasn't able to find the topic which has the solution to this, but here is what you do.

!macro A_Macro Param
!define "Check_${Param}"
!ifdef Check_Hello
# do something here
!else
# ...
!endif
!undef "Check_${Param}"
!macroend


This would check if the user passed "Hello".

-Stu

Stu, you are the best, thanks!


I never tried this, but can symbol names have spaces?

-dandaman32


Yes, if you put quotes around them. Their usage in instructions is weird though: you don't need to put quotes around the ${symbol w/ spaces}:


OutFile Test.exe

!define "AB CD" 1234

Section
MessageBox MB_OK ${AB CD}
SectionEnd