[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:56:14 CEST

Simon Large wrote:
> Joseph Galbraith wrote:
>>>> --- 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.
>
> I thought that had always been the case, but I am fairly new to C++.

No... it has been years since it was the case in the
standard, but MS has been a bit slow to catch up (mostly
because they have legacy code.)

This patch is bringing the TSVN code base into compliance
with this new rule.

> I can't see the need for an initialiser before the loop. Why not just:
>
> + int i;
> + for (i=m_nSearchIndex; ...

You are correct, the initializer is unneeded in this case.

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:52:06 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.