极品prefixing与函数(无效) [英] Need for prefixing a function with (void)

查看:109
本文介绍了极品prefixing与函数(无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我跨不寻常的编码规范,其中要求一个函数返回作废是(无效)pfixed $ P $来了。

I recently came across a rather unusual coding convention wherein the call for a function returning "void" is prefixed with (void).

例如。

(void) MyFunction();  

时从函数调用就像任何不同:

Is it any different from the function call like:

MyFunction();  

有它有什么优势或者是另一个不必要的,但有编码某种约定?

Has it got any advantage or is it yet another needless but there coding convention of some sort?

推荐答案

如printf某些功能()返回几乎从未在现实code使用的值(在printf的情况下,打印的字符数) 。然而,一些工具,例如皮棉,想到如果一个函数返回一个值,它必须使用,并会抱怨,除非你写的东西,如:

Some functions like printf() return a value that is almost never used in real code (in the case of printf, the number of characters printed). However, some tools, like lint, expect that if a function returns a value it must be used, and will complain unless you write something like:

int n = printf( "hello" );

使用无效转换:

(void) printf( "hello" );

告诉你真的不想使用返回值这样的工具,从而使他们安静的方式。如果不使用这些工具,你不必理会,并且在任何情况下,大多数工具允许您将它们配置为特定函数忽略返回值。

is a way of telling such tools you really don't want to use the return value, thus keeping them quiet. If you don't use such tools, you don't need to bother, and in any case most tools allow you to configure them to ignore return values from specific functions.

这篇关于极品prefixing与函数(无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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