Mail Archives: djgpp/1997/08/02/11:34:45
Nate Eldredge wrote:
> I don't dare describe it as a bug, but IMHO it's at
> least a misfeature. The problem is that scanf("%e",...)
> (or %f, or %g) reads a float. But if you use upper case,
> it reads a double instead (or a long double if you use
> an `l' already). As a workaround, to read a double, use
> the standard %le format.
> Can somebody with a copy of the ANSI standard enlighten
> us as to whether this is supposed to happen? There is
> already a bug with formats like %LG, for which I posted
> a patch some time ago.
From Plauger's "The Standard C Library", which quotes the
ANSI standard, in scanf only the letters 'e', 'f' and 'g'
(lowercase) are supported for floating point conversion.
If you want a double then you prefix them with 'l' (lower-
case 'L') and for a long double you use upper-case 'L'.
[ANSI Standard X3.159-1989, section 7.9.6.2, paraphrased]
It also says that "The conversion specifiers E, G and X
are also valid and behave the same as, respectively, e, g
and x" [7.9.6.2]. (But not, interestingly, F.)
So to be ANSI compliant, the options are:
%e, %f, %g float
%le, %lf, %lg double
%Le, %Lf, %Lg long double
and the uppercase conversion specifiers (%E, %F and %G) may
not be at all portable if you expect it to read a double or
long double (and it may also break ANSI-conforming programs,
if they expect E and G to input into a float). In fact, this
is the way in which the OSF/1 C library (which is not the GNU
one) interprets it, as per the standard...
Chris C
- Raw text -