Need for prefixing a function with (void)

前端 未结 6 1864
一向
一向 2020-12-03 23:32

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

e.g.

(void)         


        
6条回答
  •  春和景丽
    2020-12-03 23:58

    If the function returns something the void could avoid (!) a warning (indeed in no way I was able to make gcc warn me that the return value is lost) on some compilers (or lint tools); but more importantly, it makes clear that a return value is "thrown" away purposely (and not by mistake).

提交回复
热议问题