objective c - "return" and stepping through a function in Xcode -
i've got nested if
statements perform data check. if result i'm looking for, store data in array , call return;
in order break out of function.
when stepping through in debugger, have noticed rather breaking out of function immediately, 1 return
call instead moves application different return
call, , then breaks out of function. question twofold:
1) why happen?
2) should worry about? hasn't caused me problems far.
here's exact code below. happens 100% of time when final return in code (look near end) reached. have put comment in code return
function goes after last one.
if ([self comparepx:[self getavgpxclrforrow:rowedge andcol:coledge fordirection:0] tobins:bgbins] == nil) { coledge--; while (coledge >= includedareaorigincol) { if ([self comparepx:[self getavgpxclrforrow:rowedge andcol:coledge fordirection:0] tobins:bgbins] != nil) { coledge++; prevedgept = cgpointmake(coledge, rowedge); [edgeptsleft addobject:[nsvalue valuewithcgpoint:prevedgept]]; //first return steps return return; } else { if ([self comparepx:[self getavgpxclrforrow:rowedge-1 andcol:coledge fordirection:0] tobins:bgbins] != nil) { prevedgept = cgpointmake(coledge, rowedge); [edgeptsleft addobject:[nsvalue valuewithcgpoint:prevedgept]]; return; } else { if (rowedge - prevedgept.y == 0) return; isfindingleftedge = no; //first return return; } } } }
that's result of compiler optimization.
there's bit of code needs run on function before going caller (possibly doing cleanups or stack manipulations, possibly de-allocations).
compiler have selected not repeat code, both "return" statements end running same assembly block, , debugger doesn't have enough information understand that.
nothing worry about.
Comments
Post a Comment