Making Assertions

F

Flash Gordon

On 24 Nov 2004 14:55:42 -0800
How do you make assertions in C code using the Visual C++ 6.0
compiler?

The same way as with any C compiler, using the assert manual. I suggest
you get and read a decent C book such as K&R second edition and the
comp.lang.c FAQ.
 
M

Malcolm

Water Cooler v2 said:
How do you make assertions in C code using the Visual C++ 6.0 compiler?

/*
makes an array sum to one.

It will assertion fail if passed fewer than one item in the array, if
passed
a null array, or if the sum is zero.
*/
void sumtounity(double *x, int N)
{
int i;
double tot = 0;

assert(N > 0);
assert(x != NULL);

for(i=0;i<N;i++)
tot += x;

assert(tot != 0.0);

for(i=0;i<N;i++)
x /= tot;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top