避免“表达式结果未使用”块中的警告
以下代码在块中的赋值操作上返回表达式未使用警告。该代码不太实用,但排除部分中有更多代码,并且这些代码必须在特定队列上运行。
__block NSNumber *pageId=nil;
dispatch_sync(_myDispatchQueue, ^{
int val;
//... code generates an int and puts it in val
pageId = [NSNumber numberWithInt:val];
}];
//pageId used below
我该如何摆脱这个错误?
The following code is returning an expression unused warning on the assignment operation in the block. The code isn't very practical, but there is a lot more code in the excluded section and that code has to run on a particular queue.
__block NSNumber *pageId=nil;
dispatch_sync(_myDispatchQueue, ^{
int val;
//... code generates an int and puts it in val
pageId = [NSNumber numberWithInt:val];
}];
//pageId used below
How do I get rid of this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的实验结果
笔记我从 Intrubidus 那里得到了这个,但我想要更多信息,所以在实验之后我在这里记录了我的发现,供下一个人使用。
仅适用于忽略和弹出之间的区域。 “-Wunused-value”不会抑制未使用的变量。
这是抑制未使用的变量的方法:
另外,没有推送和弹出,如图所示:
该文件中#pragma之后的任何位置都会忽略警告类型。这似乎仅适用于有问题的文件。
希望您觉得这很有用,
-大通
My Experimental Findings
Note I got this from Intrubidus, but I wanted additional information so after experimenting I recorded my findings here for the next guy.
Only applies to the area between the ignore and the pop. "-Wunused-value" does not suppress unused variables.
This is how you would suppress unused variables:
Also, without the push and pop, as shown:
The type of warning was ignored anywhere in that file after the #pragma. This seems to only apply to the file in question.
Hope you found this useful,
- Chase