how to print all debug(printf or cout) statements before the assert

Mailaripillai, Kannan Jeganathan (STSD) kannanmj@hp.com
Wed Jan 25 12:28:00 GMT 2012


> Are the printf/cout statements are run by separate threads?
No. Unless you have these different printf statements in two different threads.

> In the above program some time prinrf statement on line1 is printed. some 
> times upto line 2, some time upto line3. why?
It depends on whether the stdout is buffered or unbuffered.

> How to make sure that all the print statements, before the line causing 
> the crash , are printed?
Method 1: setvbuf(stdout, NULL, _IONBF, 0)
Method 2: fflush(stdout) wherever required

Regards,
Kannan

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of ranjith kumar
Sent: Wednesday, January 25, 2012 12:08 PM
To: gcc-help@gcc.gnu.org
Subject: how to print all debug(printf or cout) statements before the assert

Hi,
I have a program like

1)printf("%s %d",__FILE__,__LINE__);
2)printf("%s %d",__FILE__,__LINE__);
3)printf("%s %d",__FILE__,__LINE__);
4)assert(0);


1)My question is : are the printf/cout statements are run by separate threads?
2)In the above program some time prinrf statement on line1 is printed.
some times upto line 2, some time upto line3.
why?
3) How to make sure that all the print statements, before the line
causing the crash , are printed ?

thanks.



More information about the Gcc-help mailing list