[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: Simon Large <simon_at_skirridsystems.co.uk>
Date: 2005-08-19 20:46:22 CEST

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++.

I can't see the need for an initialiser before the loop. Why not just:

+ int i;
+ for (i=m_nSearchIndex; ...

Simon

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.tigris.org
---------------------------------------------------------------------
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:46:04 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.