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
Printable View
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
Where are you getting it?
Assert comes up when something that should be true turn out to be false. Example:
You would get an assert if a or b = nullPHP Code:ASSERT(a != NULL);
ASSERT(b != NULL);
c = a + b;
Not sure what that macro is, but there's a function called assert() that complains loudly when something's wrong.
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:
Z.Code:in debug mode...
#define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )
and in release:
#define assert(exp) ((void)0)
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
Output: First assert: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;
}
Second assert:
ERROR!! Assert x !=5 failed
on line 24
in file test1704.cpp
Done.
You forgot your line-continuation characters in the definition of ASSERT. Oh, and use <iostream> instead :)
The line-continuation characters were there but they are gone now. It is something with the php tags.
Hmmm...that's okay then :)
Er, John?
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.Code:#define Assert(a, b) assert(a && b)
INT main()
{
INT x = 2;
Assert(x != 2, "X == 2 in INT main()");
}
Z.
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!
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.
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.