c - intptr_t 和 uintptr_t 的字符串格式

intptr_t uintptr_t 的字符串格式是什么,对 32 位和 64 位架构都有效。

编辑

warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type "AAA"

这是我在 64 位而不是 32 位中收到的警告。

  intptr_t  AAA

最佳答案

这将是来自 inttypes.h 的以下宏:

对于 printf: PRIdPTR PRIiPTR PRIoPTR PRIuPTR PRIxPTR PRIXPTR

对于 scanf: SCNdPTR SCNiPTR SCNoPTR SCNuPTR SCNxPTR

使用示例:

uintptr_t p = SOME_VALUE;
printf("Here's a pointer for you: %" PRIxPTR "\n", p);

https://stackoverflow.com/questions/5795978/

相关文章:

coding-style - 线宽格式标准

emacs - 在 Emacs 中,如何在一系列初始化语句中排列等号?

android - 点后 2 位 float

python - 从 Python 日期/时间获取 "2:35pm"而不是 "02:35PM"?

c++ - 如何使用具有类似 printf 格式的 C++ std::ostream?

java - String.format 或类似的正确格式字符串

formatting - 复制/粘贴到 Word 时如何保留 rstudio 的格式?

eclipse - 格式化后无法删除 Eclipse 中的 block 注释

html - 在 Visual Studio Code 中格式化 html 代码,使属性位于不同的行

c# - 如何格式化 Visual Studio 2012 中的所有文件?