"erroneous" refers to the original algorithm, which was corrected by making a special-case fix.
The point I was trying to make is that obfuscated code attracts bugs.
As for your last question "whats wrong with it", I'd say its unneccesarily complex (=another level of ofuscating the code). Its an immensly trivial function but still you have to think twice before you figure out what its actually doing. Compared to somthing like
Code:
int CountLines(const char *str )
{
int count = 0;
while(*str != 0)
{
if(*str=='\n')
count++;
str++;
}
return count;
}
which is pretty straight forward, and just as efficient.
Perhaps its just me that thinks that (since I just wrote it) *shrug*
Im not saying that everything else is bad/ugly/wrong, I just want to point out that code has more properties than just to twiddle with bits and bytes - properties such as readability, flexibility, maintainability, and if you have a choice between two technically equivalent functions, choose the one that can be the most aid to you or your collegues.
Perhaps it's a bit off topic but code-design is something I think is immensly important. Note that the code-example is an illustration of concept, not an in-depth analysis of how to count linefeeds.
/Per
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."