Mail Archives: djgpp/1998/11/11/15:00:38
Hi,
I am not a compiler wizard but I think that I have found a bug in djgpp.
Versions:
bnu281b
djdev201
gcc281b
operating system NT 4.0 SP3
The Code:
#include <stdio.h>
main( int argc, char* argv[] )
{
printf( "aaa" ) ;
putch( 'Q' ) ; /* goes to screen not stdout */
printf ( "zzz") ;
}
Compiled with:
gcc test1.c -o test1.exe -lm
The output is:
Qaaazzz
I would expect the output to be:
aaaQzzz
Other notes:
If the program is run with
test1 > out
The character Q goes to the screen and the rest to the file.
I cannot recall if putch() is "supposed to" use stdout or not and I
have mentioned this here just in case it is.
I also tried outputting many (1000) Q's with a for loop and the order
was the same. That is Q's first.
Code fragment for this:
printf( "aaa" ) ;
for ( i=0 ; i<1000 ; i++ )
putch( 'Q' ) ; /* goes to screen not stdout */
printf ( "zzz") ;
This latter test result suggests to me that the problem may be due to
some code re-ordering due to optimisation, and not as I at first
considered due to NT returning from printf() before the output was
actually put on the display and putch() taking a shortcut and getting
there first.
I do not read the mail list but it would be nice to know if the bug is
in my analysis or in the compiler/library.
Douglas.
- Raw text -