一开始使用 Clang 是否明智?

发布于 2024-08-05 15:33:43 字数 173 浏览 12 评论 0原文

我刚刚开始使用 xcode 并学习 Objective-C 和 Objective-C。 Cocoa,将 Xcode 3.2 中的编译器替换为 Clang 以获得增强的错误检查和静态分析器会有帮助吗?我只是好奇所提供的额外内容是否会有帮助,或者坚持默认设置是否会更好地服务于我的学习?

非常感谢

加里

I am just starting out with xcode and learning Objective-C & Cocoa, would it be helpful to swap the compiler in Xcode 3.2 to Clang for the enhanced error checking and static analyser. I am just curious if the extras given would be helpful or would my learning be better served sticking to the default settings?

many thanks

gary

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦在深巷 2024-08-12 15:33:43

使用 CLANG 有几个选项:

  1. 运行构建并分析,以查看 clang
    结果。

  2. 在项目设置中
    配置,您可以检查
    “运行静态分析器”框和 CLANG
    将在每次编译时运行。

  3. 您还可以更改编译器
    从 GCC 4.x 到 CLANG/LLVM。那
    显示更多错误和 CLANG
    警告(一个例子是
    NSLog(@"A 值为 %@:%@", value)
    会警告你你没有通过
    足够的参数)。

我推荐选项 2 - 如果您在每次构建时都运行静态分析器,则不会花费更多时间,并且您会立即发现自己是否在做一些奇怪的事情,而不是稍后修复一堆错误。它为您提供的清晰信息实际上提供了很多教育价值,因此如果您刚刚学习,打开它更有意义!

选项 3 适合不时运行,因为它可以进行更多的错误检查。但是,目前 XCode 没有适用于 iPhone 设备的 CLANG/LLVM 编译器,因此您只能在为模拟器进行编译时使用该设置。最好的方法是创建名为“Debug CLANG”的调试配置副本(在项目设置配置选项卡中),并将该配置设置为使用 CLANG/LLVM 编译器并运行静态分析器。请注意,创建新配置后,您必须退出设置,将其选择为活动配置(通过右上角的下拉列表),然后返回项目设置以编辑值。

然后,在日常使用中,您只需使用“调试”设置即可使用静态分析器进行编译,并可能每周切换到“调试 CLANG”一次,以查看是否存在任何更深层次的问题。

There are a few options for using CLANG:

  1. Run build and analyze, to see clang
    results.

  2. In project settings for a
    configuration, you can check the
    "run static analyzer" box and CLANG
    will be run each time you compile.

  3. You can also change the compiler
    from GCC 4.x to CLANG/LLVM. That
    displays more errors and CLANG
    warnings (one example is that
    NSLog(@"A value is %@:%@", value)
    will warn you you are not passing in
    enough parameters).

I would recommend option 2 - if you run the static analyzer with each build, it doesn't take much more time and you'll find out if you are doing something odd right away, rather than fixing a bunch of errors later. The clear messages it give you actually provide a lot of educational value, so it makes even more sense to turn it on if you are just learning!

Option 3 is good to run from time to time because of the greater error checking. However, currently XCode has no CLANG/LLVM compiler for the iPhone device, and so you can only use that setting when compiling for the simulator. The best approach then is to create a copy of the debug configuration (in the project settings configurations tab) named "Debug CLANG", and set that configuration to use the CLANG/LLVM compiler and run the static analyser. Note that after you create a new configuration you have to back out of settings, select it as the active configuration (via the top right dropdown) and then go back in to project settings to edit the values.

Then in day to day use you simply use the "Debug" setting to compile using the static analyzer, and switch to "Debug CLANG" perhaps once a week to see if any deeper problems exist.

甜妞爱困 2024-08-12 15:33:43

您可以使用静态分析器,而无需使用实际的 Clang 编译器。通常,您不会使用分析器作为默认构建选项,因为它会稍微减慢构建时间。

然而,即使不考虑静态分析,Clang 编译器也是一个不错的选择。正如您所指出的,它具有更好的错误报告,但主要优点是它非常快,事实上在我的测试中它几乎是 GCC 的两倍。

You can use the static analyser without using the actual Clang compiler. Generally you wouldn't use the analyser as your default build option as it slows build times a fair bit.

However, the Clang compiler is a good option even without considering static analysis. It has much better error reporting as you point out, but the main advantage is that it's very fast, in fact in my testing it's almost twice as fast as GCC.

我不咬妳我踢妳 2024-08-12 15:33:43

如果您在 XCode 中“构建和分析”或打开“运行静态分析器”首选项,您将获得 Clang 的静态分析。

如果您不进行 C++ 开发,从 gcc 切换到 Clang 似乎并没有太大的缺点。您只是不需要这样做即可获得 Clang 静态分析的好处。

If you "Build and Analyze" or turn on the "Run Static Analyzer" preference in XCode, you get Clang's static analysis.

If you're not doing C++ development, there doesn't appear to be much downside to switching from gcc to Clang. You just don't need to do so to get the benefits of Clang's static analysis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文