This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Silently passing wrong input for good one


Hi Roberto,

> the program below, when compiled with GCC 4.0.2 and
> given the input "-3e-abcd", prints
>
> input = `-3e-abcd'
> good
> f = -3
> left = `abcd'

I changed this behavior during the 3.4.x development cycle (3.3.x did
behave like Comeau), see testcase num_get/get/char/10.cc. Basically, my
rationale was that of matching as closely as possible the usual usage of
scanf in C: if '-3e-' is handed to scanf, it definitely assigns -3.0 and
the user happily proceeds.

Then, we come to the detailed interpretation of C++ 22.2.2.1.2/11, where
it says: "would have caused scanf to report an input failure". In my
reading of the C standard (frankly, I have available only C99, which
sometimes is subtly different from C90, the real reference), an input
failure is a very specific kind of failure (see 7.19.6.2/4), which may
lead to scanf returning EOF (7.19.6.2/16).

Anyway, more generally, if I read again the entire 7.19.6.2 (in
particular /9 is important when it defines an input item as *a prefix*
of a matching input sequence), I don't see how possibly a scanf of a
single float can *fail* (either input failure or matching failure) when
'-3e-' is passed. Indeed, in practice, it assigns the value and returns
1, nothing externally visible signals that something went wrong.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]