开发者

Is there a way to get extra warnings (perl-like runtime,) for Objective-C?

I've been doing some programming in perl lately, and I found that it throws a really use开发者_运维问答ful warning - "Use of uninitialized value" when you try to do a compare / print / regex etc with a value that you somehow didn't initialize yet, (along with a host of other things I always didn't mean to do) and it got me wondering if there is some kind of extension or something that can give me some extra useful warnings in Objective-C?

I know with things like swizzling it would be possible to generate some runtime warnings, maybe with some clever code magic you could find a way to make Nil yell at you from time to time even, although that's tough because nil pointers need to evaluate false.

Taking it to an extreme I even think (not to start a debate here) it would be great if I could get a warning when I don't have an "else" statement at the end of a decision structure.

So to put this in a bit of a two-part question, how much of this is possible, and how much of it exists?


Yes, it depends on the compiler. Assuming you're using GCC, there's a host of warning options that you can enable. Compiling with the -Wall -Wextra -pedantic options is a good choice—if your code compiles warning-free with those options, that's a great start (though of course it does not guarantee defect-free code).

If you're using Xcode as a frontend to GCC, then you can enable those warning options via the project settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜