[CMake] ARGVn madness?!
Brad King
brad.king at kitware.com
Fri Nov 13 07:52:08 EST 2009
Michael Wild wrote:
> Looks like the scoping algorithm only "overwrites" these automatic
> variables only if they are associated with actual arguments, otherwise
> it just inherits them. Same thing happens if my_macro is a function.
> Smells like bug to me ;-)
It's behaving exactly as documented. Functions make their arguments
available as local variables using dynamic scoping. Macros have their
arguments substituted into the implementation and then executed in the
invoking context (the function's scope in this case).
> This probably means, always check ARGC and only use ARGN to retrieve
> optional arguments...
Or, check ARGC and don't index ARGVx for x >= ARGC. This is the same
as is needed for argc and argv[] in C. No one blindly indexes argv[x]
for x >= argc.
-Brad
More information about the CMake
mailing list