What's the best way to fix warnings from unused result

Fred Wright fw at fwright.net
Sun Apr 7 21:35:43 UTC 2019

On Sun, 7 Apr 2019, Hal Murray wrote:

>> Does a simple void cast work?  E.g.:
>>  	(void) strerror_r(...)
> I haven't found the magic using that approach.
> ../../ntpd/nts.c:214:16: warning: ignoring return value of ???strerror_r???,
> declared with attribute warn_unused_result [-Wunused-result]
>         (void) strerror_r(errno, errbuf, sizeof(errbuf));
>                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That's too bad; so you need to fix it the "hard way" after all.

It seems like a compiler bug to warn in that case.  Presumably the intent 
of the warning is to let you know that you're *unintentionally* ignoring
a result.  The void cast makes it clear that it's intentional.

Fred Wright

More information about the devel mailing list