如何在gcc中打印UINT64_t?

时间:2015-05-07 05:48:21

标签: c function unix

为什么此代码不起作用?

#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

3 个答案:

答案 0 :(得分:8)

uint64_t在标准整数类型头文件中定义。即,stdint.h。 首先,在您的计划中加入stdint.h

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

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

您也可以参考此问题How to print a int64_t type in C

答案 1 :(得分: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

一起使用

答案 2 :(得分:1)

添加:

#include <inttypes.h>

并使用PRIu64(在引号之外):

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