This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430-GCC-opensource:printf 格式字符串长度修饰符"hhh"未在 newlib 中实现

Guru**** 2585275 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1004019/msp430-gcc-opensource-printf-format-string-length-modifier-hh-not-implemented-in-newlib

器件型号:MSP430-GCC-opensource

目前、宏 PRIu8解析为"hhu"、而 newlib 的 printf()实现似乎不支持该操作。

这同样适用于其它 PRI*8宏。 _intsup.h 将宏_int8定义为"hhhh"。  我想这在技术上是正确的、因为"Hh" 对于宽度 char_bits 类型应该是正确的、但它与 newlib 一起中断。

快速搜索表明、此问题也出现在其他平台上:

使用 printf 8位格式宏进行回归(narkive.com)

inttypes.h 宏 PRIu8在 cortex M0·问题#70·platformio/platform-atmelsam·gitHub 上生成错误的格式字符串

我意识到 newlib 的 printf()具有与 POSIX 版本相对的修整功能集,因此可能不支持“hh”长度修饰符。 在这种情况下、我建议在 MSP430平台上将宏__INT8解析为"h"。 这可能不符合 POSIX 标准、但目前也不是预期的接收器。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Thilo、

    感谢您的建议。 我将把这一情况传达给我的同事。

    BR、

    Leo