octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #35852] fscanf does not read full file


From: Roman Hiestand
Subject: [Octave-bug-tracker] [bug #35852] fscanf does not read full file
Date: Tue, 12 Jun 2012 09:35:29 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0

Follow-up Comment #22, bug #35852 (project octave):

Yes, I found the following quote In "The C++ Programming Language" by Bjarne
Stroustrup, (I have the third edition), chapter 21.6.2 "Input Streams and
Buffers":

The putback() function allows a program to put an unwanted character back to
be read some other time, as shown in §21.3.5. The unget function puts the
most recently read character back. Unfortunately, backing up an input stream
is not always possible. For example, trying to back up past the first
character read will setios_base::failbit. What is guaranteed is that you can
back up one character after a successful read.

I was also trying to find the respective hint in the documentation for
libstdc++, but it's not very clear there. In the entry for
std::basic_istream::putback I found:

If rdbuf() is not null, calls rdbuf()->sputbackc(c).
If rdbuf() is null or if sputbackc() fails, sets badbit in the error state.

In the documentation for std::basic_streambuf::sputbackc() I found 

Similar to sungetc(), but __c is pushed onto the stream instead of the
previous character. If successful, the next character fetched from the input
stream will be __c. 

It states that it can fail, but doesn't specify in what cases.

I found other interesting documents on the web:
http://stackoverflow.com/questions/6152956/are-there-any-guarantees-with-unget
http://bytes.com/topic/c/answers/62925-unget-vs-putback

My personal summary: Calling putback() once after get() is guaranteed to work,
but not more. If you really want to be platform-independent (and I think you
should), you should eliminate successive calls to putback().
Alternatively, since Octave seems to have its own streambuf class
(c_file_ptr_buf), you could extend it to allow for more putback()s.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?35852>

_______________________________________________
  Nachricht gesendet von/durch Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]