开发者

What is this kind of coding style in c?

(void) fputs( line, stdout );
(void) alarm( TIMEOUT );

The above appea开发者_如何学运维rs in the function body,I've never seen such code before...


It's a form of coding to debugging tools at the expense of human beings reading your code, and it's Considered Harmful. In particular, the classic lint tool and perhaps some compilers generated warnings if you did not use the return value of a function that returned a value, and the only way to suppress this locally was to cast the result to void.

Either ignore it, or fix it (remove the useless void casts) if you have sufficient authority to do so.


The only thing unusual are the casts to void. It's a way to indicate that you're going to ignore the return value of the function, or to indicate that a function returns no value. Some compilers warn about ignored return values, so can be a way around that warning. I don't think it's very good style myself.


If you mean the (void) part, then that is explicitly discarding the result of the function call. fputs(...) returns an int. (void) fputs(...) discards the int return value without generating compiler warnings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜