visual studio 2010 - C++ VS2010 Debugger behaves weirdly on loop variable beyond loop scope -
i bit puzzled, since seems c++ debugger in vs2010 behaving bit oddly. if go , run this:
int = 100; for(int = 0; < 5; i++) { printf("value of inside loop: %d", i); } printf("value of outside loop: %d", i);
then, when breakpointing on line after last 1 above , hovering cursor above "i" variable, debugger shows value 5.
however, if decide send "i" variable parameter method:
test(100); void test(int i) { for(int = 0; < 5; i++) { printf("value of inside loop: %d", i); } printf("value of outside loop: %d", i); }
then, when breakpointing on last line , hover mouse on "i", i, debugger shows value 100.
could enlight me on (or test on machine). bug or feature or missing something?
thanks in advance!
update: make things clear - actual program prints , executes intended, debugger shows unexpected values. so, 1 can ignore says "printf", have been involving variable "i".
it's bug. asking debugger tell value of variable, i
. there 2 variables of name in current stack frame. debugger giving wrong 1 (which out of scope). because local variable debug symbols not generated each scope, each stack frame.
don't that, it's bad idea. confuse you, or if not you, programmer comes after you, confused debugger.
it should generate warning c6244.
it best new projects specify /wall /wx
, is, enable warnings , treat warnings errors.
Comments
Post a Comment