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: sungetc


>>>>> "Joe" == Joe Buck <Joe.Buck@synopsys.com> writes:

>> 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.

I think you misunderstood my point.  I was complaining about the
specification of the return value, not the size of the putback buffer.
IMO, if we can put back a character, we should return that character.
Currently, if we do a putback when we are at the beginning of the read
buffer, we return 0, whereas if we are in the middle of the read buffer we
return the character.

[lib.streambuf.reqts] says that there is a putback position iff _M_in_cur >
_M_in_beg; this is not the same as the magic putback buffer, which is an
implementation detail.

Jason


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