好介绍到<&inttypes.h GT; [英] Good introduction to <inttypes.h>

查看:107
本文介绍了好介绍到<&inttypes.h GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想推荐使用< inttypes.h> 来有人做的printf 混合32 / 64位的基础之上。我想谷歌的介绍或教程页面的几个例子和使用指南,但我无法找到一个。

I want to recommend the use of <inttypes.h> to someone doing printf with mixed 32/64 bit builds. I tried to Google an introduction or tutorial page with a few examples and usage guidelines, but I couldn't find one.

有人可以推荐的介绍或教程&LT; inttypes.h&GT;

Can someone recommend an introduction or tutorial for <inttypes.h>?

推荐答案

尝试<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html\">http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html作为一个开始。

如何使用新的便携式格式宏一个更好的例子是在 AVR-libc的<发现/ A>。我已经包括(从链接)为例来说明。 QNX库也有更好的人类可读的说明(如果你不喜欢阅读说明书冷),虽然你有近滚动到页的末尾去描述的肉。

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:


  • (前三个字母)

    • PRI的printf格式

    • SCN为scanf的格式为:


    • x为十六进制格式

    • u代表无符号格式

    • o为八进制格式

    • 我的整数格式化

    • d为十进制格式


    • 8八位

    • 16 16位

    • 32 32位

    • 64 64位

    • FAST8为快八位

    • FAST16为快16位

    • FAST32为快32位

    • FAST64为快64位

    • LEAST8为至少八位

    • LEAST16为至少16位

    • LEAST32为至少32位

    • LEAST64为至少64位

    • PTR为指针

    • MAX最大支持位尺寸

    所以 PRIx8 表示printf格式指令格式为十六进制的八位。

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

    这篇关于好介绍到&lt;&inttypes.h GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆