On Wed, Jan 25, 2012 at 1:37 AM, ranjith kumar <ranjithproxy@xxxxxxxxx> wrote: > 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 ? Asserts are diagnostic aides, which are suppose to help the programmer [1, 2]. assert calls abort(), which is useless (especially under a debugger). In release code (ie, when NDEBUG is defined), assertions are not compiled into the program. But some folks leave asserts in their production code [3], which is a mis-use of the diagnostic and leads to a DoS on a server. Try the following for sane behavior when using asserts. Your program won't crash, and you can continue stepping to see how it handles negative test cases. Jeff [1] www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf [2] http://pubs.opengroup.org/onlinepubs/000095399/functions/assert.html [3] http://www.isc.org/software/bind/advisories/cve-2011-4313 # define ASSERT(exp) { \ if(!(exp)) { \ std::ostringstream oss; \ oss << "Assertion failed: " << (char*)(__FILE__) << "(" \ << (int)__LINE__ << "): " << (char*)(__func__) \ << std::endl; \ std::cerr << oss.str(); \ raise(SIGTRAP); \ } \ }