Results 1 to 12 of 12

Thread: assertion

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    assertion

    Im getting the error "debug assertion failed" I looked it up in the help file but it doesn't really explain it. anyway does anyone know what the cause of it is? thanks
    Matt

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Where are you getting it?
    Assert comes up when something that should be true turn out to be false. Example:

    PHP Code:
    ASSERT(!= NULL);
    ASSERT(!= NULL);
    b
    You would get an assert if a or b = null
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not sure what that macro is, but there's a function called assert() that complains loudly when something's wrong.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Zaei
    Guest
    i think "assert" is a macro too. Otherwise, when you build in Release mode, you would get a speed hit from parameter passing, even if nothing took place, if you had a lot of asserts all over.

    Ah, here it is:
    Code:
    in debug mode...
    #define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )
    
    and in release:
    #define assert(exp)     ((void)0)
    Z.

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    assert() is a macro too.
    Here is one way of defining it yourself:
    PHP Code:
    #define DEBUG
         #include <iostream.h>

         #ifndef DEBUG
            #define ASSERT(x)
       #else
           #define ASSERT(x) \
                    
    if (! (x)) \                { \
                       
    cout << "ERROR!! Assert " << #x << " failed\n"; \
                       
    cout << " on line " << __LINE__  << "\n"; \
                     
    cout << " in file " << __FILE__ << "\n";  \
                   }
       
    #endif 
    PHP Code:
      int main()
        {
           
    int x 5;
           
    cout << "First assert: \n";
           
    ASSERT(x==5);
           
    cout << "\nSecond assert: \n";
           
    ASSERT(!= 5);
           
    cout << "\nDone.\n";
         return 
    0;
     } 
    Output: First assert:

    Second assert:
    ERROR!! Assert x !=5 failed
    on line 24
    in file test1704.cpp
    Done.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You forgot your line-continuation characters in the definition of ASSERT. Oh, and use <iostream> instead
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    The line-continuation characters were there but they are gone now. It is something with the php tags.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hmmm...that's okay then

    Er, John?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Zaei
    Guest
    Code:
    #define Assert(a, b) assert(a && b)
    
    INT main()
    {
       INT x = 2;
       Assert(x != 2, "X == 2 in INT main()");
    }
    Game Programming Gems has a section on writing custom assert macros, with stuff like an "Ignore Always" option, and the one I just typed. Great stuff.

    Z.

  10. #10
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78
    I got an assertion error when the program (I guess, because it said the problem was with fseek.c,) was trying to use fseek! Look!

    #include <fstream.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include <stdio.h>

    void main(void) {
    FILE *testafile;
    char myfilechar;
    testafile = fopen("D:\testfile.fil", "r");
    myfilechar = (char) fseek(testafile, 4, 0);
    fclose(testafile);
    printf("%c", myfilechar);
    }

    What is up with this! What in the #$%#$%#$ is assertion doing there in the first place! It is so ridiculous!

    Anyway, enough of my ranting and raving about this sometimes BS-ing language--it's the only one out there close to decent. But can somebody help me out with and/or explain to me this problem? Thank you! Geesh!
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I can imagine two reasons why fseek should assert:
    a) the FILE* you pass is NULL
    b) the third argument is an invalid value

    a happens when fopen fails, that is, either the file you specified does not exist and you have a don't create mode (like "r"), or the mode you specified is invalid (like "sdf" would be, but "r" could be too, maybe you need a b or t afterwards ("rt" or "rb")),

    b happens because there are only three valid values: SEEK_SET, SEEK_END and SEEK_CUR. Those are defines for numeric values, and 0 just might not be one of them (you should use the symbolic names anyway).

    BTW the return value is of type int and only reports errors.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78
    Ah that explains alot. I think it would be issue a. This was backwhen, when I didn't know that you were supposed to use two back slashes between each name instead of one in a filename. This explains why it failed to open. Thanks.
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width