`l` 长度修饰符对后面的 a、A、e、E、f、F、g 或 G 转换说明符没有影响
`l` length modifier has no effect on a following a, A, e, E, f, F, g, or G conversion specifier
我正在尝试理解以下内容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
认为 float
和 double
之间没有区别。
printf
系列函数的参数通过variable-length 机制获取。在 variable-length 参数列表的 variable-length 部分,"default argument promotions" 适用:类型 char
和 short int
被提升为 int
,并且 float
升级为 double
.
TL;DR - 您链接的答案非常好。 printf()
中的 %f
可以处理 double
和 float
,这两种类型的参数。
信息: printf()
是一个variadic function.
根据 C99
,第 7.19.6.3 章
语法
#include <stdio.h>
int printf(const char * restrict format, ...);
关于 %f
格式说明符,
f,F
A double
argument representing a floating-point number is converted to
decimal notation in the style [−]ddd.ddd, where the number of digits after
the decimal-point character is equal to the precision specification. [....]
所以,我们看到,标准只提到了double
。对 更年轻的对手感到好奇 、float
?
然后,从第 6.5.2.2 章第 7 段开始
[...] The ellipsis notation in a function prototype declarator causes
argument type conversion to stop after the last declared parameter. The default argument
promotions are performed on trailing arguments.
并且,关于 默认参数促销 部分,(强调我的),第 6 段,
[...] If the expression that denotes the called function has a type that does not include a
prototype, the integer promotions are performed on each argument, and arguments that
have type float
are promoted to double
. These are called the default argument
promotions. [...]
所以,对于 printf()
函数,使用 %f
格式说明符,无论提供的参数是 float
还是 double
类型,它都会得到无论如何提升到 double
。
我正在尝试理解以下内容section:
l (ell)
Specifies that a following
d
,i
,o
,u
,x
, orX
conversion specifier applies to along
orunsigned long
argument; that a followingn
conversion specifier applies to a pointer to along
argument; that a followingc
conversion specifier applies to awint_t
argument; that a followings
conversion specifier applies to a pointer to awchar_t
argument; or has no effect on a followinga
,A
,e
,E
,f
,F
,g
, orG
conversion specifier.
我还可以看出这与 cppreference:fprintf 一致,其中 "%f"
和 "%lf"
等同于 printf()
系列。
所以this answer是不是错了?还是 C99
现在明确表示 "%f"
用于 float
,而 "%lf"
用于 double
用于 printf()
系列功能?
文档是正确的:printf
认为 float
和 double
之间没有区别。
printf
系列函数的参数通过variable-length 机制获取。在 variable-length 参数列表的 variable-length 部分,"default argument promotions" 适用:类型 char
和 short int
被提升为 int
,并且 float
升级为 double
.
TL;DR - 您链接的答案非常好。 printf()
中的 %f
可以处理 double
和 float
,这两种类型的参数。
信息: printf()
是一个variadic function.
根据 C99
,第 7.19.6.3 章
语法
#include <stdio.h>
int printf(const char * restrict format, ...);
关于 %f
格式说明符,
f,F
A
double
argument representing a floating-point number is converted to decimal notation in the style [−]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. [....]
所以,我们看到,标准只提到了double
。对 更年轻的对手感到好奇 、float
?
然后,从第 6.5.2.2 章第 7 段开始
[...] The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.
并且,关于 默认参数促销 部分,(强调我的),第 6 段,
[...] If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type
float
are promoted todouble
. These are called the default argument promotions. [...]
所以,对于 printf()
函数,使用 %f
格式说明符,无论提供的参数是 float
还是 double
类型,它都会得到无论如何提升到 double
。