[prog] C programming - capturing information sent to stdout

Kathryn Hogg kjh at flyballdogs.com
Thu Jul 14 12:20:57 EST 2005


Conor Daly said:
> On Wed, Jul 13, 2005 at 08:59:16AM +1000 or so it is rumoured hereabouts,
> Sue Stones thought:
>> Kathryn Hogg wrote:
>>
>> >  assert(newfd == 1);
>>
>> The assert is a new thing to me, so I read up on it of course.  Are
>> there stylistic boundaries on when and where it should be used?
>
> Basically, assert does something like:
>
> if(! foo) {
>   panic;
> }
>
> assert does a test.  If the test fails, the program halts with a hopefully
> useful error message.  It should be used liberally for debugging anywhere
> in your code where you expect a variable to be a certain value.

Or not be a particular value:

int func(X *x)
{
    assert(x != 0);

    return *x;
}

if the assertion fails, it calls abort() which will generate a core dump
-- which can make post mortem analysis easier.

Some people say to use assertions liberally in development/testing and
then turn it off in production by compiling with "-DNDEBUG"

>
> That's not very well explained at all...


-- 
Kathryn
http://womensfooty.com



More information about the Programming mailing list