Making Assertions

Discussion in 'C Programming' started by Water Cooler v2, Nov 24, 2004.

  1. How do you make assertions in C code using the Visual C++ 6.0 compiler?
    Water Cooler v2, Nov 24, 2004
    #1
    1. Advertising

  2. Water Cooler v2

    Flash Gordon Guest

    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.
    Flash Gordon, Nov 24, 2004
    #2
    1. Advertising

  3. Water Cooler v2

    Malcolm Guest

    "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;

    assert(tot != 0.0);

    for(i=0;i<N;i++)
    x /= tot;
    }
    Malcolm, Nov 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vhdlcohen
    Replies:
    0
    Views:
    1,069
    vhdlcohen
    Dec 1, 2004
  2. anupam
    Replies:
    2
    Views:
    925
  3. Razvan
    Replies:
    4
    Views:
    1,064
    javakid
    Oct 20, 2004
  4. Razvan

    Proper use of assertions

    Razvan, Oct 7, 2004, in forum: Java
    Replies:
    5
    Views:
    488
  5. P. Chalin

    use of assertions in practice

    P. Chalin, Mar 26, 2005, in forum: Java
    Replies:
    0
    Views:
    400
    P. Chalin
    Mar 26, 2005
Loading...

Share This Page