Undefined Variables : Compile-Run-Kaboom

Happily working along and doing some refactoring... app starts crashing hard at main(). What the 16d?


Quite a bit of stepping line by line by line with breakpoints galor and found that Xcode is happy to compile and link with an undefined variable. Sorta seems like the basic job of a compiler is to make sure that variables exist, make space for them on the stack, little things like that. But understandably since Xcode is a new product, only 16 yrs old, still a kid, oddities can be expected (really?).


Ok, so I flushed the neverending corruption of "DerivedData" with the "Clean" menu item. Built, Xcode thinks undefined variable is "a-ok" and kaboom! Then did the "Clean" the right way and deleted the whole DerivedData folder with Xcode not running. Undefined OK! Kaboom!


The constant battle with Xcode just got elevated to a new level. Can't trust the output now either. Xcode 7.2 See links for example.


Complied, running, up to line with undefined variable:

<img src="https://www.evernote.com/l/ACDq-bkFFCtO9qrpYQ1rM78Des5WIkQU5GgB/image.png" alt="Undefined_variable_compiles" />


Step one more time, Kaboom!

<img src="https://www.evernote.com/l/ACDuAyW9ScxKPYcYQLvvLnkLmlEJMow4R30B/image.png" alt="step-kaboom" />


Never been a fan of blindly using nil objects (and the exceptions to that being OK) but a nil variable is a new one. 😮

Replies

Ok, a little follow up.

In my code:

theRecoveryHandler = [ self.blocksArray objectAtIndex: index ];


In NSArray.h

- (ObjectType)objectAtIndex:(NSUInteger)index;


and then in usr/include strings.h

char *index(const char *, int) __POSIX_C_DEPRECATED(200112L);


so NSUInteger can be a char * ?

You do not show the value of self.blocksArray at the point where execution is paused. Are you sure that is not the variable that has been deallocated and is causing the crash?