I try to print a variable of type int64_t
using %lld
format specifier but get the following warning?
Warning: format '%lld' expects type 'long long int', but argument 4
has type 'int64_t'
In my opinion, under linux, the int64_t
is always long long int
, then:
- Why does this warning occur?
- How can I fix this?
Best Answer
Use
PRId64
: (Don't forget to include<inttypes.h>
)Use
PRIx64
and proper cast if you want to print it as hex.C99 onwards (link to draft, Page 22), C specs suggest the type
long long int
should be atleast 64 bits but it may be more also.On some platforms,
long long int
might be 128-bit and the print statement invokes UB on such platforms.So treat this warning as a portability issue warning.