On the previous topic of uninitialized pointers in methods in Objective-C - GCC3 will actually give you warnings on those variables if you've got your targets setup as 'deployment' instead of 'development'.
Apparently GCC3 disables (at least) the uninitialized variable warnings when you've got -O0 (no optimisations) set. Any other optimisation value and the compiler properly gives you warnings.
Don't ask me why - but I tried it and it seems to work.
The relevant flag is -Wuninitialized. I believe it's on by default, but GCC 3 ignores it if the optimizer is off (i.e. you are doing a Development build).
I don’t quite understand what Victor Ng is on about. Objective-C ivar pointers are initialized to nil, and you should get a compiler warning if you attempt to use an uninitialized local variable.
It turns out that when you allocate the object instance, the ObjC runtimewill initialize all of your instance variables to 0 or nil.
To quote:
The alloc method dynamically allocates memory for the new object's instance variables and initializes them all to 0[~]all, that is, except the isa variable that connects the new instance to its class.
So what the heck was going on with my stuff? Here's my test case:
-(void)testIdInitTest { id obj; [self assertTrue:(obj == nil) message:@"obj should be nil if pointers are initialized"]; }
.. and it always fails.
What's going on here is that (as the doc's say) the 'alloc' method is the thing doing the initialization. Since we never alloc an object, the 'obj' pointer is never initialized to nil.
Annoying - but true.
Regardless - thanks to Michael for pointing out my errors.
5:09:17 PM