I'm trying to compare numerical values of two pointers with ">=" operator but instead of comparing them it adds some random values to the first.
void obj::Loader::calculate_size(const char* start_ptr, const char* end_ptr, atomic_long& v, atomic_long& vt, atomic_long& vn, atomic_long& f) {
while (start_ptr >= end_ptr) {
if (*start_ptr == 'v') {
start_ptr++;
if (*start_ptr == ' ') {
v++;
start_ptr += 27;
}
else if (*start_ptr == 't') {
vt++;
start_ptr += 18;
}
else if (*start_ptr == 'n') {
vn++;
start_ptr += 21;
}
}
else if (*start_ptr == 'f') {
start_ptr++;
if (*start_ptr == ' ') {
f += 3;
start_ptr += 17;
}
}
start_ptr++;
}
}
This function is supposed to count all instances of these letters in a part of a memory-mapped file (from "start_ptr" to "end_ptr"). Knowing the minimal length at certain portions of the file I decided to increment the "start_ptr" by more than one sometimes but by doing that I can't rely on "!=" operator to stop the loop.
The problem is ">=" doesn't really work as it would on integers and it just crashes the whole thing. Are there any alternatives?