printf 长度修饰符 %L 是标准的(或未来的标准)吗?

Is printf length modifier %L standard (or future standard)?

根据 cppreference.com,长度修饰符 %L 仅对浮点类型有效。但是现代 GNU 编译器和库似乎也接受整数作为 %ll(long long)的同义词。 cppreference 是否有可能在这方面出错?或者整数的 %L 将来会成为标准吗?

来自最新的 C11 草案 N1570,§7.21.6.1 第 7 节:

L -- Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

所以您的来源是正确的,L 作为 长度修饰符 仅为 浮点数 转换定义。我不希望这会在未来的版本中改变,因为根本没有必要。只需使用 lll 即可。

C11 标准 in §7.21.6.1 7 列出了有效的长度修饰符。

标准中唯一提及 L 作为长度修饰符的是 long double 类型:

L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

此外,§7.31 Future Library Directions中没有提到这一点:

7.31.11 Input/output < stdio.h >

  • 1 Lowercase letters may be added to the conversion specifiers and length modifiers in fprintf and fscanf. Other characters may be used in extensions.

  • 2 The use of ungetc on a binary stream where the file position indicator is zero prior to the call is an obsolescent feature.

并且,L 的相同用法也适用于 the POSIX StandardL 是一个长度修饰符,仅用于 long double 类型。