output redirection bug

Richard B. Kreckel kreckel@ginac.de
Wed May 10 12:05:00 GMT 2000


Hi,

I compiled current gcc from CVS with libstdc++ v3 enabled and am having
the following problem: Compiling hello.c using c++ (not gcc) does not
produce the second "Hello, world!\n" line when output is redirected into
some file:
-------------------8<--------------------------8<----------------
#include <stdio.h>

int main(void)
{
    printf("Hello, world!\n");
    fflush(stdout);
    printf("Hello, world!\n");
    return(0);
}
------------------->8-------------------------->8----------------
This only happens when I link dynamically against libstdc++.so.3, not when
I link statically.  Here is the end of some strace output:
-------------------8<--------------------------8<----------------
[40162331] fstat(1, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[4015fa0d] mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400d3000
[40158974] write(1, "Hello, world!\n", 14) = 14
[401588dd] close(1)                     = 0
[401588dd] close(0)                     = 0
[401588dd] close(2)                     = 0
[401588dd] close(1)                     = -1 EBADF (Bad file descriptor)
[401588dd] close(0)                     = -1 EBADF (Bad file descriptor)
[401588dd] close(2)                     = -1 EBADF (Bad file descriptor)
[40158974] write(1, "Hello, world!\n", 14) = -1 EBADF (Bad file descriptor)
[4015fa51] munmap(0x400d3000, 4096)     = 0
[4014cb4d] _exit(0)                     = ?
------------------->8-------------------------->8----------------
My (clueless) guess is this is some static deinitialization problem with
cout, cin, cerr being destroyed (twice?) before the last line is flushed
out?

Regards
    -richy.
-- 
Richard Kreckel
<Richard.Kreckel@Uni-Mainz.DE>
< http://wwwthep.physik.uni-mainz.de/~kreckel/ >




More information about the Libstdc++ mailing list