[FFmpeg-devel] On signedness of AV_NOPTS_VALUE constant
Michael Bradshaw
mbradshaw at sorensonmedia.com
Tue Sep 18 22:11:02 CEST 2012
On Tue, Sep 18, 2012 at 1:58 PM, Reimar Döffinger
<Reimar.Doeffinger at gmx.de> wrote:
> 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.
I'd be in favor of this (assuming it fixes the warning), as I get
those warnings too and had to put casts everywhere to keep the warning
count at zero, as the project required.
--Michael
More information about the ffmpeg-devel
mailing list