gpt4 book ai didi

C 警告(clang 编译器) "integer literal is too large to be represented in a signed integer"

转载 作者:行者123 更新时间:2023-12-03 12:42:37 25 4
gpt4 key购买 nike

我有这段代码

#include <stdio.h>

typedef signed long long v2signed_long
__attribute__ ((__vector_size__ (sizeof(signed long long) * 2)));

int main()
{
v2signed_long v = {4611686018427387904LL, -9223372036854775808LL};

printf("%lli, %lli\n", v[0], v[1]);
return 0;
}

给出以下警告(相关问题没有帮助):

:7:45: warning: integer literal is too large to be represented in
a signed integer type, interpreting as unsigned
[-Wimplicitly-unsigned-literal]
v2signed_long v = {4611686018427387904LL, -9223372036854775808LL};

有没有办法解决这个警告?谢谢!

最佳答案

问题是 -9223372036854775808LL 实际上不是整数文字。它是应用了一元 - 运算符的文字 9223372036854775808LL。值 9223372036854775808 太大而不适合 signed long long,这就是您收到警告的原因。

您可以改用表达式 -9223372036854775807LL - 1LL 来解决这个问题。值 9223372036854775807 适合 signed long long-9223372036854775807LL 一样,然后减去 1 即可得到所需的值。

或者,您可以使用宏LLONG_MIN

关于C 警告(clang 编译器) "integer literal is too large to be represented in a signed integer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60323203/

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