用C忽略返回值 [英] Ignoring return values in C

查看:327
本文介绍了用C忽略返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始使用不起毛的静态code分析。
其中一个警告,我得到有时是关于这个问题。
比方说,比如,我已经得到了以下功能:

Lately, I started using lint for static code analysis. One of the warning I get sometimes is regarding this issue. Let's say for instance that I've got the following function:

uint32_t foo( void );

和我们说,我delibertly忽略函数的返回值。
为了使警告dissapear,可以写

And let's say that I delibertly ignore the return value of the function. To make the warning dissapear, one can write

(void) foo();

我的问题是,什么是正确的方式来写code这个样子,我应该继续,因为我总是这样,因为编译器不会抱怨,或者我应该用虚空的清晰度,因此其他code维护者就知道我delibertly忽略了返回值。

My question is, what is the "proper" way to write code like this, should I continue as I always did, since the compiler doesn't complain about it, or should I use the void for clarity, so other code maintainer will know that I delibertly ignored the return value.

当我看着code所示(虚空),它看起来pretty怪我......

When I look at the code like this ( with the void ), it looks pretty strange to me...

推荐答案

的常用方法是只是调用富(); 无铸造成 (无效)

The common way is to just call foo(); without casting into (void).

他从来没有谁忽略的printf()的返回值,先拿石头。

He who has never ignored printf()'s return value, cast the first stone.

这篇关于用C忽略返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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