[CMake] ARGVn madness?!

Marcel Loose loose at astron.nl
Fri Nov 13 08:06:09 EST 2009


Hi Brad, Michael,

Your explanation makes sense. I hadn't run into this problem before, and
assumed I could safely access ARGVn, whether or not n >= ARGC. Turns out
I was just lucky. I'll use ARGN instead.

Thanks,
Marcel Loose.

On Fri, 2009-11-13 at 07:52 -0500, Brad King wrote:
> 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