I have the following method in a template class (a simple FIFO queue) and while GDB debugging, I found that the statement to reassign the pointer 'previous' to 'current' seems to do nothing. previous starts as NULL and current is not NULL when this statement is executed, yet previous remains as NULL. Has anyone seen anything like this before?
inline int search(QueueEntry<T> *current,QueueEntry<T> *previous, unsigned long long t)
{
while(current && !(current->getItem()->equals(t)))
{
previous = current; //**this line doesn't seem to work**
current = current->getNext();
}
if(current)
return 1;
return 0;
}
The assignment is optimized away by the compiler because it doesn't have any effect on the function's behavior. You reassign previous
every time through the loop, but do nothing else with it.
The bug, if any, is in the rest of the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With