[FFmpeg-devel] [PATCH] checkasm: Silence warnings about unused return value from read()

Martin Storsjö martin at martin.st
Fri Aug 5 09:18:05 EEST 2022


On Wed, 27 Jul 2022, Andreas Rheinhardt wrote:

> Swinney, Jonathan:
>> This patch looks good to me. I would appreciate its merging.
>>

>  } while (0)
>  #define PERF_STOP(t) do {                               \
> +    int ret;                                            \
>      ioctl(sysfd, PERF_EVENT_IOC_DISABLE, 0);            \
> -    read(sysfd, &t, sizeof(t));                         \
> +    ret = read(sysfd, &t, sizeof(t));                   \
> +    (void)ret;                                          \
>  } while (0)

> Why do you use this extra variable instead of just casting the return
> value of read to void?

Because if I just cast the return value of read to void, it still warns 
about it being unused, at least with GCC 9. I believe the rules for "used 
vs unused" for variables (where you can cast it to void to mark it as 
used) and "must not ignore return value" (-Wunused-result) differ. 
Apparently, in order to appease the compiler for a return value to not be 
ignored, it either has to be stored or compared.

// Martin



More information about the ffmpeg-devel mailing list