Why cast unused return values to void?

后端 未结 9 1261
暗喜
暗喜 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:00

    The true reason for doing this dates back to a tool used on C code, called lint.

    It analyzes code looking for possible problems and issuing warnings and suggestions. If a function returned a value which was then not checked, lint would warn in case this was accidental. To silence lint on this warning, you cast the call to (void).

提交回复
热议问题