Return acting like break in XCode 3.2.2
Return acting like break in XCode 3.2.2
- Subject: Return acting like break in XCode 3.2.2
- From: Andrei Freeman <email@hidden>
- Date: Mon, 24 May 2010 23:16:22 -0400
Hello All-
I'm posting this here because I think the problem may lie in either a build setting or a link issue.
I have the source code to a framework which is then linked into an application. After a change today to the code the framework code began to fail in a very strange manner.
Given the following code: (Please note there are some pseudocode liberties taken)
NSArray *myArray = somePre-established array;
NSString *aString = nil;
NSEnumerator *anEnum = [myArray objectEnumerator];
while ((aString = [anEnum nextObject])) {
if ([aString isEqualToString:@StringThatMatchesObjectIndex(0)]) {
return aString;
}
return nil;
This was working fine before I changed some random code elsewhere in the program. Afterwards the "return aString " turned into a 'break'
The program counter definitely was doing a successful compare and hitting the return. But then the program counter was simply breaking from the loop and then hitting the return nil;
So the first return wasn't being honoured.
I changed the above code to:
NSArray *myArray = somePre-established array;
NSString *aString = nil;
NSString *retString = nil;
NSEnumerator *anEnum = [myArray objectEnumerator];
while ((aString = [anEnum nextObject])) {
if ([aString isEqualToString:@StringThatMatchesObjectIndex(0)]) {
retString = aString;
break;
}
return retString;
And it works fine.
However, This style of code exists throughout the framework source. So I'd rather find why this occurred than go back and correct every block that may have a scoped return.
The only other piece of potentially relevant information is that this example came from a .mm file. So I don't know whether or not this is a Obj-C++ annoyance.
Any tips gladly welcomed.
-Andrei Freeman
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden