|
-
Jul 13th, 2001, 02:30 PM
#1
Thread Starter
Hyperactive Member
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 
-
Jul 13th, 2001, 05:03 PM
#2
Frenzied Member
Where are you getting it?
Assert comes up when something that should be true turn out to be false. Example:
PHP Code:
ASSERT(a != NULL);
ASSERT(b != NULL);
c = a + 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

-
Jul 14th, 2001, 01:58 AM
#3
Monday Morning Lunatic
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
-
Jul 14th, 2001, 03:29 AM
#4
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.
-
Jul 14th, 2001, 06:57 AM
#5
Frenzied Member
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(x != 5);
cout << "\nDone.\n";
return 0;
}
Output: First assert:
Second assert:
ERROR!! Assert x !=5 failed
on line 24
in file test1704.cpp
Done.
-
Jul 14th, 2001, 07:00 AM
#6
Monday Morning Lunatic
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
-
Jul 14th, 2001, 07:06 AM
#7
Frenzied Member
The line-continuation characters were there but they are gone now. It is something with the php tags.
-
Jul 14th, 2001, 07:08 AM
#8
Monday Morning Lunatic
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
-
Jul 14th, 2001, 01:53 PM
#9
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.
-
May 17th, 2002, 05:02 PM
#10
Lively Member
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
-
May 24th, 2002, 08:57 AM
#11
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.
-
May 24th, 2002, 10:10 AM
#12
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|