什么编译器不支持“%#x”的样式在 printf 标志中?
我知道 %#x 具有与 0x%x 相同的效果,并且它符合 POSIX 标准。但人们提到有些编译器不支持它。是这样的吗,有例子吗?
I understand %#x give the same effect of 0x%x and it meets POSIX standard. But people mention that some compilers do not support it. Is that true, any example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除了一些损坏的嵌入式系统 C 库之外,
#
修饰符应该得到普遍支持。但是%#x
和0x%x
并不相同。对于值 0,它们会产生不同的结果,并且#
修饰符将始终以与十六进制数字相同的大小写打印x
(例如%#x 给出
0xa
和%#X
给出0XA
),而使用0x%X
将允许你有一个小写x
和大写十六进制数字(视觉上更令人愉悦,至少对我来说)。因此,我发现#
修饰符在实践中很少有用。Aside from perhaps some broken embedded-systems C libraries, the
#
modifier should be universally supported. However%#x
and0x%x
are not the same. They yield different results for the value 0, and the#
modifier will always print thex
in the same case as the hex digits (e.g.%#x
gives0xa
and%#X
gives0XA
) while using0x%X
would allow you to have a lowercasex
and capital hex digits (much more visually pleasing, at least to me). As such, I find the#
modifier is rarely useful in practice.%#x
是 C89、C99 和 C11 中printf
格式字符串的有效转换规范。%#x
is a valid conversion specification inprintf
format string in C89, C99 and C11.#
标志字符不是来自 POSIX,而是来自 C 标准 (§7.21.6.1)。如果编译器或库不支持它,那么它就不是 C 编译器/标准库。The
#
flag character is not from POSIX, but rather the C standard (§7.21.6.1). If a compiler or library does not support it then it is not a C compiler / standard library.根据
C
规范,这是完全有效的 -7.21.6.1 fprintf 函数
- 点#6
This is perfectly valid as per
C
Specification -7.21.6.1 The fprintf function
- point#6