[FFmpeg-devel] On signedness of AV_NOPTS_VALUE constant

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue Sep 18 21:58:30 CEST 2012


On 18 Sep 2012, at 20:49, Andrey Utkin <andrey.krieger.utkin at gmail.com> wrote:
> $ cat signedness.c
> #include <libavutil/avutil.h>
> int main() {
>  int64_t pts = 0;
>  if (pts == AV_NOPTS_VALUE)
>    return 1;
>  return 0;
> }
> 
> Compiling with -Wextra gives a warning:
> 
> $ LC_ALL= LANG= gcc -c signedness.c -Wall -Wextra
> signedness.c: In function 'main':
> signedness.c:4:11: warning: comparison between signed and unsigned
> integer expressions
> 
> Why this gives warning? The constant is defines as INT64_C(0x8000000000000000)
> Preprocessor produces such code:
> int main() {
>  int64_t pts = 0;
>  if (pts == 0x8000000000000000L)
>    return 1;
>  return 0;
> }
> 
> It is strange to me that compiler treats this constant as unsigned.

I guess it is strange, but the 0x8... constant does not fit into int64_t, so I think trying to put it into that invokes undefined behaviour.
I think it should be defined as INT64_C(-0x8000000000000000) which in practice should give the same value but avoid the undefined aspect.


More information about the ffmpeg-devel mailing list