the following code is wrong -- it does not ensure that all returned
values are of same type. It is, though, a sort of very easily-made
error (for it is conceptually pretty weird that "NSOrderedSame" is
_not_ a NSComparisonResult; same kind of problem can happen with any
enumerated constant):
#import <Cocoa/Cocoa.h>
int main() {
NSLog(@"%@",[[NSArray arrayWithObjects:@"456",@"123",@"789",nil]
sortedArrayUsingComparator:
(NSComparator)^(id a,id b){ // should be "^NSComparisonResult(id
a,id b)" of course...
if (a==b) return NSOrderedSame; // ...or at least, this should be
casted
return [a compare:b];
}
]);
return 0;
}
That it does not compile in GCC is all right.
Which does not seem to me all right is that Clang, which in theory
should give better static code analysis (or so I understand), compiles
without a glitch -- and then does not sort properly!
161 /tmp> sw_vers
ProductName: Mac OS X
ProductVersion: 10.6.1
BuildVersion: 10B504
162 /tmp> cc -Wall -framework Cocoa -fobjc-gc-only -std=gnu99 q.m && ./
a.out
q.m: In function ‘__main_block_invoke_1’:
q.m:7: error: incompatible type returning ‘NSComparisonResult’,
expected ‘int’
163 /tmp> /Developer/usr/bin/clang -Wall -framework Cocoa -fobjc-gc-
only q.m && ./a.out
2009-09-17 00:12:06.998 a.out[7725:903] (
789,
123,
456
)
164 /tmp>
Perhaps I am wrong, but I feel this is not good: given Clang is, if I
understand properly, the future, it might be perhaps an important
omission... or am I overlooking something of importance?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden