Why cast unused return values to void?

后端 未结 9 1360
暗喜
暗喜 2020-11-22 09:00
int fn();

void whatever()
{
    (void) fn();
}

Is there any reason for casting an unused return value to void, or am I right in thinking it\'s a c

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 10:03

    For the functionality of you program casting to void is meaningless. I would also argue that you should not use it to signal something to the person that is reading the code, as suggested in the answer by David. If you want to communicate something about your intentions, it is better to use a comment. Adding a cast like this will only look strange and raise questions about the possible reason. Just my opinion...

提交回复
热议问题