The joys of C++
Quick, why does this give me a compiler error?
if (dIntersectionZ < box.GetChild(0,0,0).GetBox().Min.z) Assert(false);
else if (dIntersectionZ < box.GetChild(0,0,1).GetBox().Min.z) z = 0;
else if (dIntersectionZ < box.GetChild(0,0,2).GetBox().Min.z) z = 1;
else if (dIntersectionZ <= box.GetChild(0,0,2).GetBox().Max.z) z = 2;
else Assert(false);
The compiler complains that the else in the second line does not belong to any if.
Assert isn’t a function, duh!
From MyAssert.h, included in some completely inobvious place:
#define Assert(x) if (!(x)) {printf("Error:\n File %s\n Function %s\n →
Line %i;,__FILE__,__FUNCTION__,__LINE__);{ static FILE *fOut; static char →
sName[100]; _snprintf_s(sName,99,"Error_%x.log",sName); fopen_s(&fOut,sNam →
e,"wb"); if(fOut){fprintf(fOut,"Error:\n File %s\n Function %s\n Line % →
i",__FILE__,__FUNCTION__,__LINE__);fclose(fOut);}} assert(0); exit(999);}
Moral of the story:
Preprocessor macros make for some really entertaining afternoons.
Oh, and avoid C++ wherever possible.

2 Comments for 'The joys of C++'
uuuuh. painful
“Assert()” with upper case “A” defined in “MyAssert.h” seems to be some self-made assert.
The STL-assert “assert()” is defined in “assert.h”.
That’s also just a macro but hopefuly some better made one..
Curly brackets around the body should do the job:
define Assert(x) { if(!x) ... }
Write a comment
Trackback: http://jan.varwig.org/archive/the-joys-of-c/trackback
Comment-Feed: RSS2