问题描述
为什么下面的程序会报错?
Why the following program gives an error?
#include <stdio.h>
int main()
{
unsigned int64_t i = 12;
printf("%lld\n", i);
return 0;
}
错误:
In function 'main':
5:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'i'
unsigned int64_t i = 12;
^
5:19: error: 'i' undeclared (first use in this function)
5:19: note: each undeclared identifier is reported only once for each function it appears in
但是,如果我删除 unsigned 关键字,它就可以正常工作.所以,为什么 unsigned int64_t i
会报错?
But, If I remove the unsigned keyword, it's working fine. So,Why unsigned int64_t i
gives an error?
推荐答案
您不能在 int64_t
类型上应用 unsigned
修饰符.它只适用于 char
、short
、int
、long
和 long long
.
You cannot apply the unsigned
modifier on the type int64_t
. It only works on char
, short
, int
, long
, and long long
.
您可能想要使用 uint64_t
,它是 int64_t
的无符号对应物.
You probably want to use uint64_t
which is the unsigned counterpart of int64_t
.
另请注意,int64_t
等.在头文件 stdint.h
中定义,如果你想使用这些类型,你应该包括它.
Also note that int64_t
et al. are defined in the header stdint.h
, which you should include if you want to use these types.
这篇关于为什么“无符号 int64_t"在 C 中给出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!