的很好的介绍

发布于 2024-11-14 21:50:35 字数 1539 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

撩心不撩汉 2024-11-21 21:50:35

尝试 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/ inttypes.h.html 首先。

有关如何使用新的可移植格式化宏的更好示例,请参见 avr- libc。我提供了一个示例(来自链接)来进行说明。 QNX 库也有更好的人类- 可读的描述(如果您不喜欢冷酷地阅读规范),尽管您必须滚动到页面末尾才能了解描述的实质内容。

#include <inttypes.h>

uint8_t smallval;
int32_t longval;
...
printf("The hexadecimal value of smallval is %" PRIx8
       ", the decimal value of longval is %" PRId32 ".\n",
       smallval, longval);

请注意,这使用“String”“String”隐含连接运算符来生成字符串(在此示例中)

"The hexadecimal value of smallval is %x, the decimal value of longval is %ld.\n"

尝试分解命名约定似乎表明:(

  • 前三个字母)
    • printf 格式的 PRI
    • scanf 格式的 SCN
  • (第四个字母)
    • x 用于十六进制格式
    • u 用于无符号格式
    • o 用于八进制格式
    • i 用于整数格式
    • d 用于十进制格式
  • (额外字母)
    • 8 代表八位
    • 16 代表十六位
    • 32 代表三十二位
    • 64 代表六十四位
    • FAST8 表示“快速”八位
    • FAST16 表示“快速”16 位
    • FAST32 表示“快速”三十二位
    • FAST64 表示“快速”64 位
    • LEAST8 表示“最少”八位
    • LEAST16 表示“最小”十六位
    • LEAST32 表示“最少”三十二位
    • LEAST64 表示“最少”六十四位
    • 指针的PTR
    • MAX 表示支持的最大位大小

因此 PRIx8 表示 printf 格式指令,用于格式化为十六进制八位。

Try http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html for a start.

A better example of how to use the new portable formatting macros was found in avr-libc. I've included an example (from the link) to illustrate. QNX libraries also have a better human-readable description (if you don't like reading the specification cold), although you have to scroll nearly to the end of the page to get to the meat of the descriptions.

#include <inttypes.h>

uint8_t smallval;
int32_t longval;
...
printf("The hexadecimal value of smallval is %" PRIx8
       ", the decimal value of longval is %" PRId32 ".\n",
       smallval, longval);

Note that this uses the "String" "String" implied concatenation operator to yield the string (in this example)

"The hexadecimal value of smallval is %x, the decimal value of longval is %ld.\n"

An attempt to decompose the naming convention seems to indicate:

  • (first three letters)
    • PRI for printf format
    • SCN for scanf format
  • (fourth letter)
    • x for hexadecimal formatting
    • u for unsigned formatting
    • o for octal formatting
    • i for integer formatting
    • d for decimal formatting
  • (extra letters)
    • 8 for eight bit
    • 16 for sixteen bit
    • 32 for thirty-two bit
    • 64 for sixty-four bit
    • FAST8 for "fast" eight bit
    • FAST16 for "fast" sixteen bit
    • FAST32 for "fast" thirty-two bit
    • FAST64 for "fast" sixty-four bit
    • LEAST8 for "least" eight bit
    • LEAST16 for "least" sixteen bit
    • LEAST32 for "least" thirty-two bit
    • LEAST64 for "least" sixty-four bit
    • PTR for pointer
    • MAX for maximum supported bit size

so PRIx8 means printf format instruction to format to hexadecimal eight bits.

日裸衫吸 2024-11-21 21:50:35

我总是遵循标准(PDF 链接 )对于那些事情;一旦你弄清楚它们的设置模式,它们就不会太复杂。相关部分是§7.8整数类型的格式转换

I always go to the standard (PDF link) for those things; they're not too complicated once you figure out the patterns they're set up in. The relevant section is §7.8 Format conversion of integer types <inttypes.h>.

羁绊已千年 2024-11-21 21:50:35

HP 有一个关于编写可移植代码的很好的参考,并且他们给出了一些使用 inttypes.h 的具体建议

编写可移植代码

HP Has a good reference on writing portable code and they give some specific advice for using inttypes.h

Writing Portable Code

双手揣兜 2024-11-21 21:50:35

我总是从维基百科开始查找标题。 在维基百科上似乎有很大问题。我接下来要采取的步骤是访问此网站。上一个站点列出了每个宏并给出了示例。您还可以查看此网站,它实际上向您展示了头文件。我认为这些都不是真正的教程,但它们是一个很好的起点。

I always start at Wikipedia to look up a header. <inttypes.h> seems to be very problematic on Wikipedia. The next step I would then take is going to this site. This previous site lists every macro and does give an example. You could also check out this site, which actually shows you the header file. I don't think that any of those are really tutorials per say but they are a good jumping off point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文