[prog] C programming - capturing information sent to stdout

Mary mary-linuxchix at puzzling.org
Fri Jul 15 11:33:42 EST 2005


On Fri, Jul 15, 2005, Sue Stones wrote:
> Despite what people have said about assert resulting in a core dump
> and program death, I have found that it does neither.  It prints an
> error message, and perhaps leaves the function, but the program still
> runs.  I wasn't entirely surprised because I had read that somewhere
> on the net while I was trying to understand this yesterday.  Is this a
> difference in compilers?  Could it be a difference between C and C++?

It does kind of depend on the programming language. In Python and Java,
an assert raises an error. In Python this goes up the normal exception
channels and can be caught (although I can't think of a situation where
that's good practice, aside from a unit testing reporter or something).
In Java I'm not sure.

I tested it in C with the attached C file. When run it does crash
immediately. Do you have a short counter example?

This is what happens when I compile and run the attached:

$ gcc -o assertTester /tmp/testassert.c

$ ./assertTester
assertTester: /tmp/testassert.c:5: main: Assertion `1==0' failed.
Aborted

You can see that it didn't print the line after the assert. (It also
doesn't do a core dump, I don't remember enough about gcc/C to know how
to reliably get core dumps.)

-Mary


More information about the Programming mailing list