Why cast unused return values to void?

后端 未结 9 1251
暗喜
暗喜 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 09:54

    At work we use that to acknowledge that the function has a return value but the developer has asserted that it is safe to ignore it. Since you tagged the question as C++ you should be using static_cast:

    static_cast(fn());
    

    As far as the compiler goes casting the return value to void has little meaning.

提交回复
热议问题