Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Making Assertions

Reply
Thread Tools

Making Assertions

 
 
Water Cooler v2
Guest
Posts: n/a
 
      11-24-2004
How do you make assertions in C code using the Visual C++ 6.0 compiler?
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      11-24-2004
On 24 Nov 2004 14:55:42 -0800
(Water Cooler v2) wrote:

> 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.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      11-25-2004

"Water Cooler v2" <> wrote
> 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[i];

assert(tot != 0.0);

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
want to write assertions in a seperate VHDL file anupam VHDL 2 02-15-2006 02:38 PM
use of assertions in practice P. Chalin Java 0 03-26-2005 03:16 AM
New book: SystemVerilog Assertions Handbook vhdlcohen VHDL 0 12-01-2004 06:18 PM
Assertions can be enabled/disabled programatically ? Razvan Java 4 10-20-2004 09:05 PM
Proper use of assertions Razvan Java 5 10-08-2004 02:39 PM



Advertisments