繁体   English   中英

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

[英]format '%lld' expects type 'long long int', but argument 4 has type 'int64_t'

我尝试使用%lld格式说明符打印int64_t类型的变量,但得到以下警告?

警告:格式'%lld'需要类型'long long int',但参数4的类型为'int64_t'

在我看来,在linux下, int64_t总是long long int ,然后:

  1. 为什么会出现此警告?
  2. 我怎样才能解决这个问题?

怎么修?

使用PRId64 :(不要忘记包含<inttypes.h>

printf("var64 = %" PRId64 "\n", var64);

如果要将其打印为十六进制,请使用PRIx64和正确的PRIx64

int64_t总是long long int ,那为什么会出现这个警告呢?

从C99开始( 链接到草稿 ,第22页),C规范建议long long int类型应至少为 64位,但也可能更多。

- long long int类型的对象的最小值
LLONG_MIN -9223372036854775807 // - (2 63 -1)
- long long int类型的对象的最大值
LLONG_MAX +9223372036854775807 // 2 63 - 1

在某些平台上, long long int可能是128位,print语句在这些平台上调用UB

因此,将此警告视为可移植性问题警告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:格式&#39;%llx&#39;期望的参数类型为&#39;long long unsigned int *&#39;,但是参数3的类型为&#39;off64_t *&#39;[-Wformat] 格式&#39;%ld&#39;期望类型为&#39;long int&#39;,但是参数3的类型为“ TEST” 警告:格式&#39;%lu&#39;期望参数类型为&#39;long unsigned int&#39;,但是参数4的类型类型为&#39;long unsigned int *&#39;[-Wformat] 警告:格式&#39;%ld&#39;期望类型为&#39;long int&#39;的参数,但是参数2的类型为&#39;int&#39; 警告:格式&#39;%d&#39;需要类型为&#39;int&#39;的参数,但参数2的类型为&#39;long int&#39;[-Wformat =] Re Legacy代码:格式&#39;%d&#39;需要类型为&#39;int&#39;的参数,但参数3的类型为&#39;long unsigned int&#39;[-Wformat] 警告:格式&#39;%ld&#39;期望类型为&#39;long int&#39;的参数,但参数类型为&#39;__builtin_neon_di&#39; 格式 %lu 需要类型为“long unsigned int”的参数,但参数 3 的类型为 long long unsigned int,从打印机转换为不同大小的整数 警告:字段宽度说明符 &#39;*&#39; 需要类型为 &#39;int&#39; 的参数,但参数 2 的类型为 &#39;size_t&#39; {aka &#39;long unsigned int&#39;} 打印size_t:格式&#39;%lu&#39;期望类型为&#39;long unsigned int&#39;的参数
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM