gpt4 book ai didi

c - 格式 '%lld' 需要类型 'long long int' ,但参数 4 的类型为 'int64_t'

转载 作者:IT王子 更新时间:2023-10-29 00:16:44 26 4
gpt4 key购买 nike

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

Warning: format '%lld' expects type 'long long int', but argument 4 has type 'int64_t'

在我看来,在linux下,int64_t总是long long int,那么:

  1. 为什么会出现此警告?
  2. 我该如何解决这个问题?

最佳答案

how to fix?

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

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

使用 PRIx64如果您想将其打印为十六进制,则进行适当的转换。

int64_t is always long long int, then why does this warning occur?

C99 以后( link to draft ,第 22 页),C 规范建议类型 long long int应该是至少 64 位,但也可能更多。

— minimum value for an object of type long long int
LLONG_MIN -9223372036854775807 // −(263−1)
— maximum value for an object of type long long int
LLONG_MAX +9223372036854775807 // 263− 1

在某些平台上,long long int可能是 128 位并且打印语句调用 UB在这样的平台上。

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

关于c - 格式 '%lld' 需要类型 'long long int' ,但参数 4 的类型为 'int64_t',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31534474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com