c - `l` 长度修饰符对后面的 a、A、e、E、f、F、g 或 G 转换说明符没有影响

标签 c printf language-lawyer c99 format-specifiers

我试图理解以下 section :

l (ell)

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long or unsigned long argument; that a following n conversion specifier applies to a pointer to a long argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.

我也可以看出这与cppreference:fprintf是一致的其中 "%f""%lf" 等同于 printf() 系列。

this answer也是如此错误的?还是 C99 明确指出 "%f" 用于 float,而 "%lf" 用于对于 double 对于 printf() 系列函数?

最佳答案

文档是正确的:printf 认为 floatdouble 之间没有区别。

printf 系列函数的参数通过可变长度机制获取。在可变长度参数列表的可变长度部分,应用“默认参数提升”:类型 charshort int 被提升为 intfloat 被提升为 double

关于c - `l` 长度修饰符对后面的 a、A、e、E、f、F、g 或 G 转换说明符没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528346/

相关文章:

c++ - 全局变量的静态初始化是否在 `main()`之前完成?

c++ - 编译标志不适用静态链接库

c - 如何在不编写完整解析器的情况下将部分源程序转换为库调用?

在外部事件发生之前阻止读取操作的正确方法?

c - 同时打印多个整数

c++ - std::tuple sizeof,是不是错过了优化?

c - 在 c 中的循环内获取用户输入时,通过将 char * buffer 分配给 '\n' 来清除缓冲区是错误的吗?

c - 变量参数不打印

c - 包含行和列的乘法表

c++ - 我可以在模板参数中声明一个 constexpr lambda 吗?