(void)printf vs printf [英] (void) printf vs printf

查看:140
本文介绍了(void)printf vs printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clcs


我注意到有人喜欢在printf调用之前添加(void),

喜欢:(void)printf(" Timeout\\\
");而其他人则不然。所以

有人可以告诉我是否有任何收益可以为printf添加

(无效)。


谢谢,

Whatluo。

Hi, c.l.cs

I noticed that someone like add (void) before the printf call,
like: (void) printf("Timeout\n"); while the others does''t. So
can someone tell me whether there any gains in adding
(void) to printf.

Thanks,

Whatluo.

推荐答案

文章< 11 ********* *************@g44g2000cwa.googlegroups .com> ;,

whatluo< wh ***** @ gmail.com>写道:
In article <11**********************@g44g2000cwa.googlegroups .com>,
whatluo <wh*****@gmail.com> wrote:
我注意到有人喜欢在printf调用之前添加(void),
喜欢:(void)printf(" Timeout \\\
");而其他人则不然。所以有人可以告诉我在printf中添加
(void)是否有任何好处。
I noticed that someone like add (void) before the printf call,
like: (void) printf("Timeout\n"); while the others does''t. So
can someone tell me whether there any gains in adding
(void) to printf.




它可以使编译器静音(或者支持 - 单独的lint程序)警告

表示函数的结果已被丢弃。


此外,如果程序员特别小心检查

错误条件在每个地方都可能出现错误,那么printf()上的
a(无效)可能是一个缺少错误的信号

检查那一个陈述是故意的设计决定

而不是被忽视的东西。

-

历史是一堆碎片 - Laurie Anderson



It can silence a compiler (or stand-alone "lint" program) warning
that the result of a function has been thrown away.

Also, if the programmer is being particularily careful to check
error conditions at every place errors can occur, then
a (void) on the printf() can be a signal that the lack of error
checking on that one statement is a deliberate design decision
instead of something that was overlooked.
--
History is a pile of debris -- Laurie Anderson


文章< 11 ********************** @ g44g2000cwa.googlegroups .com>,

" whatluo" < WH ***** @ gmail.com>写道:
In article <11**********************@g44g2000cwa.googlegroups .com>,
"whatluo" <wh*****@gmail.com> wrote:
clcs

我注意到有人喜欢在printf调用之前添加(void),如:(void)printf (QUOT; Timeout\\\
");而其他人则不然。所以
有人可以告诉我在printf中添加
(void)是否有任何好处。
Hi, c.l.cs

I noticed that someone like add (void) before the printf call,
like: (void) printf("Timeout\n"); while the others does''t. So
can someone tell me whether there any gains in adding
(void) to printf.




printf返回一个值。


当函数返回一个值,程序员忽略代码时,我想知道原因。通常有两种解释:

程序员在忽略返回值时犯了一个错误,或者程序员

确实忽略了返回值。当你写的时候


printf(...);


我不知道你是否想要忽略返回值。如果你

写的


(无效)printf(...);


它告诉我那个程序员知道printf返回一个值,并且

有意识地决定忽略该值。做一些专业的

编程,尝试在一百万行其他人的b
代码中找到一些错误,你会欣赏这些东西。



printf returns a value.

When a function returns a value, and the programmer ignores the code, I
would want to know why. There are usually two explanations: The
programmer made a mistake ignoring the return value, or the programmer
did ignore the return value on purpose. When you write

printf (...);

I have no idea if you wanted to ignore the return value or not. If you
write

(void) printf (...);

it tells me that the programmer knew that printf returns a value, and
made a conscious decision to ignore that value. Do some professional
programming, try finding a few bugs in a million lines of other people''s
code, and you will appreciate such things.


Christian Bau< ch *********** @ cbau.freeserve.co.uk>写道:

#文章< 11 ********************** @ g44g2000cwa.googlegroups .com> ;,

#" whatluo" < WH ***** @ gmail.com>写道:



#>c.l.cs

#>

#>我注意到有人喜欢在printf调用之前添加(void),

#>喜欢:(void)printf(" Timeout \ nn);;而其他人则不然。所以

#>可以有人告诉我是否有任何收益添加

#> (void)to printf。



#printf返回一个值。



#当一个函数返回一个值,程序员忽略代码,我想知道为什么。通常有两种解释:

#程序员忽略了返回值时出错,或者程序员

#确实忽略了返回值。当你写这个
我经常注意到很多人检查printf的返回

而不是简单地查看终端窗口。

-

SM Ryan http:/ /www.rawbw.com/~wyrmwif/

留给天主教徒来破坏生存。
Christian Bau <ch***********@cbau.freeserve.co.uk> wrote:
# In article <11**********************@g44g2000cwa.googlegroups .com>,
# "whatluo" <wh*****@gmail.com> wrote:
#
# > Hi, c.l.cs
# >
# > I noticed that someone like add (void) before the printf call,
# > like: (void) printf("Timeout\n"); while the others does''t. So
# > can someone tell me whether there any gains in adding
# > (void) to printf.
#
# printf returns a value.
#
# When a function returns a value, and the programmer ignores the code, I
# would want to know why. There are usually two explanations: The
# programmer made a mistake ignoring the return value, or the programmer
# did ignore the return value on purpose. When you write

I routinely notice lots of people checking the return of printf
instead of simply looking at the terminal window.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Leave it to the Catholics to destroy existence.


这篇关于(void)printf vs printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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