[英]format '%lld' expects type 'long long int', but argument 4 has type 'int64_t'
I try to print a variable of type int64_t
using %lld
format specifier but get the following warning? 我尝试使用
%lld
格式说明符打印int64_t
类型的变量,但得到以下警告?
Warning: format '%lld' expects type 'long long int', but argument 4 has type 'int64_t'
警告:格式'%lld'需要类型'long long int',但参数4的类型为'int64_t'
In my opinion, under linux, the int64_t
is always long long int
, then: 在我看来,在linux下,
int64_t
总是long long int
,然后:
how to fix?
怎么修?
Use PRId64
: (Don't forget to include <inttypes.h>
) 使用
PRId64
:(不要忘记包含<inttypes.h>
)
printf("var64 = %" PRId64 "\n", var64);
Use PRIx64
and proper cast if you want to print it as hex. 如果要将其打印为十六进制,请使用
PRIx64
和正确的PRIx64
。
int64_t
is alwayslong long int
, then why does this warning occur?int64_t
总是long long int
,那为什么会出现这个警告呢?
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. 从C99开始( 链接到草稿 ,第22页),C规范建议
long long int
类型应至少为 64位,但也可能更多。
— minimum value for an object of type long long int
- long long int类型的对象的最小值
LLONG_MIN -9223372036854775807 // −(2 63 −1)LLONG_MIN -9223372036854775807 // - (2 63 -1)
— maximum value for an object of type long long int- long long int类型的对象的最大值
LLONG_MAX +9223372036854775807 // 2 63 − 1LLONG_MAX +9223372036854775807 // 2 63 - 1
On some platforms, long long int
might be 128-bit and the print statement invokes UB on such platforms. 在某些平台上,
long long int
可能是128位,print语句在这些平台上调用UB 。
So treat this warning as a portability issue warning. 因此,将此警告视为可移植性问题警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.