/* the proper way to do it
fp = fopen (FILE_NAME, "rb");
assert (fp != NULL);
No. Absolutely NOT. This is utterly broken, wrong, and
heinous. This is NOT what assert is for. At all. Arghh.
If you want, you might do:
fp = Fopen( ... );
assert( fp != NULL );
This would serve as documentation to the maintainer that
the Fopen call will never return a NULL pointer. Or you
can do things like:
for( i = 0; i < N; i++) {
...
}
assert( i == N);
This documents to the maintainer that the loop
is constructed such that it will always terminate with i
hitting the upper bound. The purpose of assert is to
validate that something you believe must be true is
in fact true. Often as pre-conditions in a function call:
void add( const int *a, const int *b, int *c, size_t N )
{
size_t i;
assert( a != NULL );
assert( b != NULL );
assert( c != NULL );
for( i = 0; i < N; i++ )
c
= a + b;
}
This is far safer than simply adding a comment that states
that none of the arguments can be a null pointer, since it
aborts when the unwary programmer attempts to pass a null
pointer. It is NOT doing validation. If you want to write
a function that validates, you can't use assert. For example:
int add( int *a, int *b, int *c)
{
int status = 0;
int A,B;
A = ( a == NULL ) ? 0 : *a;
B = ( b == NULL ) ? 0 : *b;
if( c == NULL )