This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: how to print all debug(printf or cout) statements before the assert
- From: "Mailaripillai, Kannan Jeganathan (STSD)" <kannanmj at hp dot com>
- To: ranjith kumar <ranjithproxy at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 25 Jan 2012 06:55:17 +0000
- Subject: RE: how to print all debug(printf or cout) statements before the assert
- References: <CAG9fbzZKVdULASEnFt5+M4Yt+ZaZVuXVpg=MTVWbL6BTi3RRAQ@mail.gmail.com>
> 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.