Bug#799674: Properly document l/ll length modifier for double/long double argument
On 12/28/2015 08:39 AM, Mathieu Malaterre wrote: > On Sat, Dec 26, 2015 at 4:54 PM, Michael Kerrisk (man-pages) > wrote: >> (Upstream mainatiner here.) >> >> On 09/21/2015 03:08 PM, Mathieu Malaterre wrote: >>> Package: manpages-dev >>> Version: 3.65-1 >>> Severity: wishlist >>> >>> Currenly the man page for *printf family is difficult to read with >>> regards to float, double and long double printing. The man page for >>> *scanf family is much clearer. AFAIK there is a confusion with an old >>> C89 behavior, since C99 the actual way to print a double is "lf" and >>> "llf" for long double. >>> >>> Right now it reads as: >>> >>> l (ell) A following integer conversion corresponds to a >>> long int or unsigned long int argument, or a following n conversion >>> corresponds to a pointer to a long int argument, or a following c >>> conversion corresponds to a wint_t argument, or a >>> following s conversion corresponds to a pointer to wchar_t argument. >>> >>> Accordingly 'll' and 'L' may need to be updated. >> >> So, I looked at this report, and I can't understand what the problem >> is that is being reported. What precisely do you think needs fixing? > > It should be clear from the documentation that one should use "lf" to > print/scan to/from a double. > > I'll copy/paste a better written comment from SO > > [...] > Since С99 the matching between format specifiers and floating-point > argument types in C is consistent between printf and scanf. It is > > %f for float > %lf for double > %Lf for long double > > However, when arguments of type float are passed to variadic functions > (as variadic parameters) such arguments are implicitly converted to > type double. This is the reason why in printf format specifiers %f and > %lf are equivalent and interchangeable. In printf you can "cross-use" > %lfwith float or %f with double. > > But there's no reason to actually do it in practice. Don't use %f to > printf arguments of type double. It is a widespread habit born back in > C89/90 times, but it is a bad habit. Use %lf in printffor double and > keep %f reserved for float arguments. > > > http://stackoverflow.com/a/28222471/136285 > [...] I'm still puzzled. In the spec for fprintf(), I see: 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. In other words, the standard is explicit that %lf is the same as %f. What am I missing? Thanks, Michael > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Bug#799674: Properly document l/ll length modifier for double/long double argument
On Sat, Dec 26, 2015 at 4:54 PM, Michael Kerrisk (man-pages) wrote: > (Upstream mainatiner here.) > > On 09/21/2015 03:08 PM, Mathieu Malaterre wrote: >> Package: manpages-dev >> Version: 3.65-1 >> Severity: wishlist >> >> Currenly the man page for *printf family is difficult to read with >> regards to float, double and long double printing. The man page for >> *scanf family is much clearer. AFAIK there is a confusion with an old >> C89 behavior, since C99 the actual way to print a double is "lf" and >> "llf" for long double. >> >> Right now it reads as: >> >> l (ell) A following integer conversion corresponds to a >> long int or unsigned long int argument, or a following n conversion >> corresponds to a pointer to a long int argument, or a following c >> conversion corresponds to a wint_t argument, or a >> following s conversion corresponds to a pointer to wchar_t argument. >> >> Accordingly 'll' and 'L' may need to be updated. > > So, I looked at this report, and I can't understand what the problem > is that is being reported. What precisely do you think needs fixing? It should be clear from the documentation that one should use "lf" to print/scan to/from a double. I'll copy/paste a better written comment from SO [...] Since С99 the matching between format specifiers and floating-point argument types in C is consistent between printf and scanf. It is %f for float %lf for double %Lf for long double However, when arguments of type float are passed to variadic functions (as variadic parameters) such arguments are implicitly converted to type double. This is the reason why in printf format specifiers %f and %lf are equivalent and interchangeable. In printf you can "cross-use" %lfwith float or %f with double. But there's no reason to actually do it in practice. Don't use %f to printf arguments of type double. It is a widespread habit born back in C89/90 times, but it is a bad habit. Use %lf in printffor double and keep %f reserved for float arguments. http://stackoverflow.com/a/28222471/136285 [...]
Bug#799674: Properly document l/ll length modifier for double/long double argument
(Upstream mainatiner here.) On 09/21/2015 03:08 PM, Mathieu Malaterre wrote: > Package: manpages-dev > Version: 3.65-1 > Severity: wishlist > > Currenly the man page for *printf family is difficult to read with > regards to float, double and long double printing. The man page for > *scanf family is much clearer. AFAIK there is a confusion with an old > C89 behavior, since C99 the actual way to print a double is "lf" and > "llf" for long double. > > Right now it reads as: > > l (ell) A following integer conversion corresponds to a > long int or unsigned long int argument, or a following n conversion > corresponds to a pointer to a long int argument, or a following c > conversion corresponds to a wint_t argument, or a > following s conversion corresponds to a pointer to wchar_t argument. > > Accordingly 'll' and 'L' may need to be updated. So, I looked at this report, and I can't understand what the problem is that is being reported. What precisely do you think needs fixing? Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Bug#799674: Properly document l/ll length modifier for double/long double argument
Package: manpages-dev Version: 3.65-1 Severity: wishlist Currenly the man page for *printf family is difficult to read with regards to float, double and long double printing. The man page for *scanf family is much clearer. AFAIK there is a confusion with an old C89 behavior, since C99 the actual way to print a double is "lf" and "llf" for long double. Right now it reads as: l (ell) A following integer conversion corresponds to a long int or unsigned long int argument, or a following n conversion corresponds to a pointer to a long int argument, or a following c conversion corresponds to a wint_t argument, or a following s conversion corresponds to a pointer to wchar_t argument. Accordingly 'll' and 'L' may need to be updated.