2015-05-07 27 views
-1

为什么这段代码不工作?如何在gcc中打印UINT64_t?

#include <stdio.h> 
main() 
{ 
    UINT64_t ram = 90; 
    printf("%d""\n", ram); 
} 

我得到了以下错误:

In function \u2018main\u2019 
error: \u2018UINT64_t\u2019 undeclared (first use in this function) 
error: (Each undeclared identifier is reported only once 
error: for each function it appears in.) 
error: expected \u2018;\u2019 before \u2018ram\u2019 
+1

'#包括'和'uint64_t' – Gopi

+0

我再次得到了同样的错误。 – Ramakant

+0

你是否改变'uint64_t'? – Gopi

回答

4

uint64_t在标准整数类型的头文件中定义。即,stdint.h。 所以首先在您的程序中包含stdint.h

然后你可以使用格式说明"%"PRIu64来打印你的价值:即

printf("%" PRIu64 "\n", ram); 

你可以参考这个问题也How to print a int64_t type in C

+3

尽管在''中定义了'uint64_t',而'PRIu64'等宏定义在''中。通常,''有效地包括'';没有其他标准C头包含另一个。 –

+0

[如何打印uint64_t?](http://stackoverflow.com/q/8132399/995714) –

2

全部工作示例:http://ideone.com/ttjEOB

#include <inttypes.h> 
#include <stdint.h> 
#include <stdio.h> 

int main() 
{ 
    uint64_t ram = 90; 
    printf("%" PRIu64 "\n", ram); 
} 

你忘了一些标题,错误地写入uint64_t并且不能使用%duint64_t

1

地址:

#include <inttypes.h> 

并使用PRIu64(引号外,像这样):

printf("%"PRIu64"\n", ram);