MikeSchinkel
25th December 2005 03:08 UTC
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
Afrow UK
25th December 2005 10:55 UTC
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
MikeSchinkel
25th December 2005 18:33 UTC
Stu, you are the best, thanks!
dandaman32
25th December 2005 22:12 UTC
I never tried this, but can symbol names have spaces?
-dandaman32
deguix
26th December 2005 13:33 UTC
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