This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Problem with template...
- From: Jean-Sebastien Vachon <js dot vachon at videotron dot ca>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 12 Sep 2002 08:33:23 -0400
- Subject: Problem with template...
Hi,
One of my co-worker has developped a template to instantiate a HashTable
and until recently everything was fine.
However, in the last few days he added a simple line (legitimate) that
cause all kind of problems on Linux but runs fine on Windows (I don't
know for other Unixes)
Here is the code...
template <class T_Key, class T_HashObj>
void HashTable<T_Key, T_HashObj>::Remove(T_Key oHKey, T_HashObj* poHObj)
{
int nHash = Hash(oHKey);
if (mpapoHashBuckets[nHash])
{
HashElement* poHsbl = NULL;
BucketObject* poDelete = NULL;
BucketObject* poCurrent =
(BucketObject *) mpapoHashBuckets[nHash]->GetHead();
while (poCurrent)
{
poDelete = poCurrent;
poHsbl = (HashElement *) poCurrent->GetObj();
poCurrent = poCurrent->GetNext();
if (poHsbl &&
mfEqualFnctn(poHsbl->GetKey(), oHKey) &&
poHsbl->GetHashObjRef() == poHObj)
{
mpapoHashBuckets[nHash]->Remove(poDelete);
HDelete poHsbl;
poHsbl = NULL;
mnHashObjs--; // <==== NEW LINE
}
}
}
}
I don't know why but when I step in the code down to this point and then
look at the execution step by step.. the new line is executed twice.
poCurrent starts with a valid pointer and poCurrent->GetNext() returns
NULL. The if (within the while) is executed as it should but when the
while condition is evaluated a second time, it jumps to NEW LINE before
exiting the function.
I tried reorganising the while loop but the problem is still there.
Any idea?
I am using GCC 3.1 on a i686-Linux (RedHat 7.2) system. The debugger I
used to step into the code is the latest release of GDB (5.2.1 installed
yerterday)
Thanks for you time.