From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8128 invoked by alias); 20 Jan 2002 00:44:57 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 8058 invoked from network); 20 Jan 2002 00:44:51 -0000 Received: from unknown (HELO out016.verizon.net) (206.46.170.92) by sources.redhat.com with SMTP; 20 Jan 2002 00:44:51 -0000 Received: from verizon.net ([151.196.177.64]) by out016.verizon.net (InterMail vM.5.01.04.02 201-253-122-122-102-20011128) with ESMTP id <20020120004450.HULW13368.out016.verizon.net@verizon.net>; Sat, 19 Jan 2002 18:44:50 -0600 Message-ID: <3C4A12C6.8EB0E4C0@verizon.net> Date: Sat, 19 Jan 2002 16:44:00 -0000 From: "Hillel (Sabba) Markowitz" X-Mailer: Mozilla 4.79 [en]C-CCK-MCD BA45DSL (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Claudio Bley CC: Claudio Bley , gcc-help@gcc.gnu.org Subject: Re: g++ newbie prblem - gcc-3.0.3 vs gcc-2.95.3 References: <3C483172@webmail.bcpl.net> <15432.16992.134224.726476@wh2-19.st.uni-magdeburg.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-01/txt/msg00205.txt.bz2 Claudio Bley wrote: > > >>>>> "Hillel" == Hillel (Sabba) Markowitz writes: > > Hillel> The following program builds and runs fine under 2.95.3 > Hillel> but does not compile under gcc-3.0.3 As a g++ newbie I > Hillel> must be doing something very obvious wrong. > > Hillel> Please respond via e-mail as I do not usually have access > Hillel> to the mailing list archive. > > Hillel> #include #include #include > Hillel> #include #include > Hillel> main() { ofstream *fout = new ofstream (dup(1)); *fout << > Hillel> "Hello World\n"; } > > [snip] > > The C++ Standard does *not* specify a facility to assign a file > descriptor to a file stream because file descriptors are OS dependent. > > If you want to redirect standard I/O channels you should assign the > stream buffers of stream objects to each other: > > ostream ostr(0); > ostr.rdbuf (cout.rdbuf ()); > > Claudio Thank you for your response. I tried your suggestion and it does work. However, we need to be able to outprint the results of fprintf to stderr (legacy code already written). If the user specifies on the command line that he wants to use a log file instead of stderr, then we want to close the stderr and open the log file. In the command line parser we have close(2); fopen(logFile, "w"): >From that point on, all fprintf(stderr, "..."); calls will be written to the log file (or the screen if the command line switch did not trigger the close and reopen. g++-2.95.3 implemented this correctly, but g++3.0.3 do not. Is there a recommended way to code this. I would prefer not to have to change all the fprintf legacy code if I can avoid it. It would be preferable if the code change also handled cerr<< ...; as well as this is a mixed c, c++ set of routines and has both legacy and new code. However, the main question is with the fprintf. As before, please respond to sabbahem@bcpl.net or Sabba.Hillel@verizon.net as I do not have reliable access to the mailing list. -- Said the fox to the fish, "Join me ashore". The fish are the Jews, Torah is our water. Hillel (Sabba) Markowitz sabbahem@bcpl.net, Sabba.Hillel@verizon.net