[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Fwd: [TSVN][PATCH]C++ standard compliant loop header scopes

From: Joseph Galbraith <galb_at_vandyke.com>
Date: 2005-08-19 20:44:10 CEST

>> --- TortoiseMerge/MainFrm.cpp (revision 4159)
>> +++ TortoiseMerge/MainFrm.cpp (working copy)
>> - for (int i=m_nSearchIndex;
>> i<m_pwndLeftView->m_arDiffLines->GetCount(); i++)
>> + int i = 0;
>> + for (i=m_nSearchIndex;
>> i<m_pwndLeftView->m_arDiffLines->GetCount(); i++)

Without more context, I can't tell for sure, but this
code probably actually used the value left in i by
the loop after the loop.

With the new rules, if i is declared as part of the for
loop, it goes out of scope when the for loop does.

So code that does something like:

for(int i = 0; i < arr.GetSize(); i++)
{
   if ( arr[i] == something )
     break;
}

if ( i == arr.GetSize() )
{
    // something wasn't found
}

// use arr[i] for something...

has to be changed as in the above exmple.

Thanks,

Joseph

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Fri Aug 19 20:36:47 2005

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.