if(self = [super init]) - LLVM警告!你是怎么处理它的? [英] if(self = [super init]) - LLVM warning! How are you dealing with it?

查看:133
本文介绍了if(self = [super init]) - LLVM警告!你是怎么处理它的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用LLVM的Xcode 4之前,这没有引起注意。条件内的赋值是完全有意的,也是一个Cocoa成语。

Prior to Xcode 4 with LLVM this passed the compiler unnoticed. Assignment within the conditional is perfectly intentional and a Cocoa idiom.

选择了LLVM编译器的Xcode 4永远不会抱怨,而不仅仅是在编译时,只要你输入它就会出现黄色警告图标。将警告视为错误而忽略警告似乎不是一个好主意。将分配移出括号会浪费空间。必须为每个新项目用pragma关闭此警告将变得乏味。

Xcode 4 with LLVM compiler selected never fails to complain, and not just at compile time, as soon as you type it the yellow warning icon appears. Turning off warnings as errors and just ignoring the warning doesn't seem like a good idea. Moving the assignment out of the parentheses wastes space. Having to turn off this warning with a pragma for every new project will become tedious.

你是如何处理它的?新的成语是什么?

How are you dealing with it? What's the new idiom going to be?

推荐答案

这实际上是一个非常古老的警告,默认情况下它只是关闭GCC和与Clang 1.6。 Xcode实际上应该给你一个如何解决它的建议 - 即括号加倍。

This is actually a very old warning, it was just off by default with GCC and with Clang 1.6. Xcode should actually give you a suggestion for how to fix it - namely, double the parentheses.

if ((self = [super init])) { ... }

额外的一对parens告诉编译器你真的做了打算在条件中进行作业。

The extra pair of parens tells the compiler that you really did intend to make an assignment in the conditional.

这篇关于if(self = [super init]) - LLVM警告!你是怎么处理它的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆