You're right. The declaration of nItems should be outside, however the assignment will still work inside.
size_t nItems = 0;
for(resbuf *pRbTemp = mpHead ; pRbTemp != NULL ; pRbTemp = pRbTemp->rbnext, ++nItems)
{
if(idx == nItems)
return pRbTemp;
}
... do lots of work
for(nItems =0, resbuf *pRbTemp = mpHead ; pRbTemp != NULL ; pRbTemp = pRbTemp->rbnext, ++nItems)
{
if(idx == nItems)
return pRbTemp;
}