🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.lib.bug
Article #527

Strange Stream Behavior

#527
From: eric%bnrmtl%IRO.UMONTREAL.CA
Date: Fri, 02 Jun 1989 15:41
67 lines
2103 bytes
A colleague has a strange problem trying to use libg++ 1.35 streams.
He sends me the following description.

---------------------------------------------------------------------------
/* Why does third item on line marked "BUG!" (line 27) not get printed? */

#include <stream.h>
#include <stdio.h>

class counter
{
  private:
    unsigned int value;
  public:
    counter(int init=5);
        counter( counter& );
    ~counter();
    unsigned int operator+ (counter);
};

main()
{
        int k ;

        counter c1;
        counter c2(7);

        // removing next line will result in core dump instead
        printf("int = %d\n", k);

        cout << "BUG!    "  << (c1+c2) << " Why not printed? \n";
        cout << "\n";

        // IF preceding/following 2 lines switched, get other results!!
        k = c1+c2;
        cout << "No bug  " << k     << " Printed. \n";
}

counter::counter(int init)
{
        value = init;
        cout << form("constructor %d\n", value);
}

counter::counter( counter& i )
{
        value = i.value;
    cout << form("call-by-value %d\n", value);
}

counter::~counter()
{
        cout << form("destructor %d \n", value);
}

unsigned int counter::operator+ (counter other)
{
        return value + other.value;
}

----------------------------------------------------------------------------


 ----------------------------------------------------------------------------
  Eric Brunelle  |    "C'est la nuit qu'il est beau de croire a la lumiere."
  BNR-Montreal   |                               -- E. Rostand
 ----------------------------------------------------------------------------
Technical Details
Message-ID: <8906021541.AA08113@bnrmtl.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!MITVMA.MIT.EDU!eric%bnrmtl%IRO.UMONTREAL.CA

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!MITVMA.MIT.EDU!eric%bnrmtl%IRO.UMONTREAL.CA
From: eric%bnrmtl%IRO.UMONTREAL.CA@MITVMA.MIT.EDU
Newsgroups: gnu.g++.lib.bug
Subject: Strange Stream Behavior
Message-ID: <8906021541.AA08113@bnrmtl.com>
Date: 2 Jun 89 15:41:01 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 67