嗯,你是谁PRIu64? [英] Mmh, who are you PRIu64?
问题描述
我是 C 的新手,我遇到了:
I am new to C and I am confronted with:
#include <stdio.h>
#include <inttypes.h>
int main(void)
{
uint64_t foo = 10;
printf("foo is equal to %" PRIu64 "!
", foo);
return 0;
}
而且它有效!我不明白为什么?有人可以帮我解决这个问题吗?非常感谢!托尔
And it works! I don't understand why? Can somebody help me about this? Thanks a lot! torr
推荐答案
PRIu64
是 C99 中引入的格式说明符,用于打印 uint64_t
,其中 uint64_t
是(来自链接的参考页):
PRIu64
is a format specifier, introduced in C99, for printing uint64_t
, where uint64_t
is (from linked reference page):
无符号整数类型,宽度分别为 ... 64 位(仅当实现直接支持该类型时才提供)
unsigned integer type with width of ... 64 bits respectively (provided only if the implementation directly supports the type)
PRIu64
是一个字符串(字面量),例如:
PRIu64
is a string (literal), for example the following:
printf("%s
", PRIu64);
在我的机器上打印 llu
.相邻的字符串文字被连接起来,来自 C99 标准的 6.4.5 字符串文字 部分:
prints llu
on my machine. Adjacent string literals are concatenated, from section 6.4.5 String literals of the C99 standard:
在翻译阶段 6,由任何相邻字符序列和宽字符串文字标记指定的多字节字符序列连接成单个多字节字符序列.如果任何标记是宽字符串文字标记,则生成的多字节字符序列将被视为宽字符串文字;否则,将其视为字符串文字.
In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literal tokens are concatenated into a single multibyte character sequence. If any of the tokens are wide string literal tokens, the resulting multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a character string literal.
这意味着:
printf("foo is equal to %" PRIu64 "!
", foo);
(在我的机器上)是一样的:
(on my machine) is the same as:
printf("foo is equal to %llu!
", foo);
这篇关于嗯,你是谁PRIu64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!