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 _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake