This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: sungetc
- From: Joe Buck <Joe dot Buck at synopsys dot com>
- To: jason at redhat dot com (Jason Merrill)
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Wed, 17 Apr 2002 10:02:40 -0700 (PDT)
- Subject: Re: sungetc
> Working on the performance stuff, I noticed that sungetc may or may not
> return the character ungotten. The standard says
>
> If the input sequence putback position is not available, returns
> pbackfail().
>
> and then for pbackfail,
>
> Returns some value other than traits::eof() to indicate success.
>
> So if there's already a putback position, sungetc returns the character
> ungotten. If there isn't one, but we can create one, sungetc returns some
> random non-EOF value. So the only thing you can usefully do with the
> return value of sungetc is compare it to EOF. This seems like a defect to
> me. Thoughts?
You can usefully use sungetc if you know that there is never more than
one pushback character (which usually means that you know that there is
only one point or one small module that is reading the stream). That's
all you need for something like a regular expression recognizer
(e.g. flex).
Requiring an arbitrary-size stack would be a possibility, but there would
be a performance penalty.
Someone who needs arbitrary pushback could build a mechanism on top of
the stuff provided by the standard library, so only those who need the
facility pay for the cost. This seems consistent with the spirit of C++.
So no, I don't think it is a defect.