I unintentionally compiled the following statement:
manager.groupName - lastGroupName;
Instead of:
manager.groupName = lastGroupName;
I am trying to understand why the compiler does not even provide a warning for the former statement I unintentionally provided. The statement has no effect, even it if is legal to subtract pointers from one another.
Both groupName and lastGroupName are of type (NSString *). The groupName property is declared as:
@property (nonatomic, retain) NSString *groupName;
Wondering if I shoul开发者_Go百科d visit bugreporter or if there is a reason that XCode isn't providing a diagnostic.
This is a legal statement in C and thus also in Objective-C, so the compiler doesn’t have to warn about it. You could add the warning flag -Wunused-value
to the compiler settings. This warns about statements without effect like this.
Generally there are lots of flags to tell the compiler what exactly to warn about. Everybody has different ideas what is OK, and what should be warned about. If the compiler emits too many warnings they become useless.
Also note that clang does indeed produce better warning and error messages it doesn’t mean that it will automatically produce more warnings. It also has the same flags for enabling and disabling certain warnings that gcc has.
XCode doesn't have the best syntax checking, although it's supposed to be much better in the version coming out soon (4.0 I believe, in beta now).
Registered developers can download XCode 4 beta which improves syntax checking in the "clang" 2.0 front-end. You can get some of that now by selecting "llvm" with clang 1.5 as your compiler instead of GCC. Apple's current recommendation is the GCC front-end and LLVM 1.5 back-end, but then you'll still be stuck with GCC's awful error messages.
I'd recommend downloading XCode 4 and trying the code out on that. You might find some significant bugs that you can go back and fix in XCode 3 before release.
In addition, periodically doing a "Clean All" and "Compile and Analyze" will find a lot of common mistakes. Highly recommended, especially if you're stuck on something.
This is legal syntax, so no error should be expected. It does seem useless, and a high quality compiler might issue a warning.
At runtime the result is a different matter. Unless I'm misremembering this is undefined behavior unless the two pointers are the same or at least point into the same array.
精彩评论