public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Change of behaviour, or something broke in cin/streambuf behaviour between 3.3.4 and 3.4.1?
@ 2004-09-22 11:42 Andrew Walrond
  2004-09-22 13:22 ` Paolo Carlini
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Walrond @ 2004-09-22 11:42 UTC (permalink / raw)
  To: gcc

My application broke between gcc 3.3.4 and gcc 3.4.1 and I don't know quite 
what to make of it.

The code:
  #include <iostream>
  int main(int argc,char* argv[])
  {
          using namespace std;
          std::streamsize a = std::cin.rdbuf()->in_avail();
         cout << " in_avail " << a << endl;
         return 0;
 }
compile with
 gcc -lstdc++ test.cpp
run with
 echo hello | ./a.out

When compiled with gcc 3.3.4 produces

 in_avail 6

but when compiled with gcc 3.4.1 produces

 in_avail 0

Is the code using some undefined behaviour, or did something break?

Andrew Walrond

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Change of behaviour, or something broke in cin/streambuf behaviour between 3.3.4 and 3.4.1?
  2004-09-22 11:42 Change of behaviour, or something broke in cin/streambuf behaviour between 3.3.4 and 3.4.1? Andrew Walrond
@ 2004-09-22 13:22 ` Paolo Carlini
  2004-09-22 13:45   ` Andrew Walrond
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2004-09-22 13:22 UTC (permalink / raw)
  To: Andrew Walrond; +Cc: gcc

Andrew Walrond wrote:

>When compiled with gcc 3.3.4 produces
>
> in_avail 6
>
>but when compiled with gcc 3.4.1 produces
>
> in_avail 0
>
>Is the code using some undefined behaviour, or did something break?
>  
>
In my opinion, the current behavior is correct. Indeed, something changed
but didn't 'break' ;) (*) Basically, the reason is that in 3.4.x we have 
a new
unbuffered filebuf for cin, cout & co, which *improves* considerably the
correctness of the library in its interactions with stdio. This streambuf is
used, correctly, by default.

In order to get the old behavior, you can add 
std::ios::sync_with_stdio(false)
at the beginning of your program, which changes cin, cout & co to use the
buffered filebuf (the only one available in 3.3.x).

Paolo.

(*) FWIW, Icc8 agrees ;)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Change of behaviour, or something broke in cin/streambuf behaviour between 3.3.4 and 3.4.1?
  2004-09-22 13:22 ` Paolo Carlini
@ 2004-09-22 13:45   ` Andrew Walrond
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Walrond @ 2004-09-22 13:45 UTC (permalink / raw)
  To: gcc

On Wednesday 22 Sep 2004 10:59, Paolo Carlini wrote:
>
> In my opinion, the current behavior is correct. Indeed, something changed
> but didn't 'break' ;) (*) Basically, the reason is that in 3.4.x we have
> a new
> unbuffered filebuf for cin, cout & co, which *improves* considerably the
> correctness of the library in its interactions with stdio. This streambuf
> is used, correctly, by default.

Thanks Paulo (for the lightning fast response+explanation).

I'll go fix my applications :)

Andrew Walrond

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-09-22 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 11:42 Change of behaviour, or something broke in cin/streambuf behaviour between 3.3.4 and 3.4.1? Andrew Walrond
2004-09-22 13:22 ` Paolo Carlini
2004-09-22 13:45   ` Andrew Walrond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).