简体   繁体   English

格式'%lld'期望类型'long long int',但参数4的类型为'int64_t'

[英]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 ,然后:

  1. Why does this warning occur? 为什么会出现此警告?
  2. How can I fix this? 我怎样才能解决这个问题?

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 always long 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 − 1 LLONG_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.

相关问题 警告:格式&#39;%llx&#39;期望的参数类型为&#39;long long unsigned int *&#39;,但是参数3的类型为&#39;off64_t *&#39;[-Wformat] - warning: format ‘%llx’ expects argument of type ‘long long unsigned int *’, but argument 3 has type ‘off64_t *’ [-Wformat] 格式&#39;%ld&#39;期望类型为&#39;long int&#39;,但是参数3的类型为“ TEST” - format ‘%ld’ expects type ‘long int’, but argument 3 has type “TEST” 警告:格式&#39;%lu&#39;期望参数类型为&#39;long unsigned int&#39;,但是参数4的类型类型为&#39;long unsigned int *&#39;[-Wformat] - warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'long unsigned int *' [-Wformat] 警告:格式&#39;%ld&#39;期望类型为&#39;long int&#39;的参数,但是参数2的类型为&#39;int&#39; - warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' 警告:格式&#39;%d&#39;需要类型为&#39;int&#39;的参数,但参数2的类型为&#39;long int&#39;[-Wformat =] - warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=] Re Legacy代码:格式&#39;%d&#39;需要类型为&#39;int&#39;的参数,但参数3的类型为&#39;long unsigned int&#39;[-Wformat] - Re Legacy code : format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat] 警告:格式&#39;%ld&#39;期望类型为&#39;long int&#39;的参数,但参数类型为&#39;__builtin_neon_di&#39; - warning: format '%ld' expects argument of type 'long int', but argument has type '__builtin_neon_di' 格式 %lu 需要类型为“long unsigned int”的参数,但参数 3 的类型为 long long unsigned int,从打印机转换为不同大小的整数 - format %lu expects argument of type 'long unsigned int' but argument 3 has type long long unsigned int, cast from printer to integer of different size 警告:字段宽度说明符 &#39;*&#39; 需要类型为 &#39;int&#39; 的参数,但参数 2 的类型为 &#39;size_t&#39; {aka &#39;long unsigned int&#39;} - warning: field width specifier '*' expects argument of type 'int', but argument 2 has type 'size_t' {aka 'long unsigned int'} 打印size_t:格式&#39;%lu&#39;期望类型为&#39;long unsigned int&#39;的参数 - printing size_t: format '%lu' expects argument of type 'long unsigned int'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM