> -----Original Message-----
> From: Martin Sebor [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 22, 2006 8:02 PM
> To: [email protected]
> Subject: Re: Windows infrastructure for generating
> VisualStudio projects and solution(s)
>
> The problem is not with the linking of the library, it comes
> up when compiling library headers that make assumptions about
> the scope of the for loop's controlling variable. Consider
> this algorithm defined in some public library header (i.e.,
> one that can be included by a program, such as <algorithm>):
>
> inline void
> some_algorithm (int __nloops)
> {
> for (int __i = 0; __i != __nloops; ++__i)
> do_something (__i);
>
> for (int __i = 0; __i != __nloops; ++__i)
> do_something_else (__i);
> }
>
> The algorithm will compile with no errors or warnings when
> the /Zc:forScope is used but will cause a diagnostic when it's not.
I have been tested this example with MSVC 7.1 with Warning Level 4
(highest possible) and haven't any diagnostics (warnings) :)
And no any warnings issued even in that case:
inline void
some_algorithm (int __nloops)
{
for (int __i = 0; __i != __nloops; ++__i)
do_something (__i);
for (int __i = 0; __i != __nloops; ++__i)
do_something_else (__i);
do_something_else (++__i);
}
The warning issued at the line with do_something_else (__i); in the
following case:
inline void
some_algorithm (int __nloops)
{
int __i = 5;
for (int __i = 0; __i != __nloops; ++__i)
do_something (__i);
do_something_else (__i);
}
warning C4288: nonstandard extension used : '__i' : loop control
variable declared in
the for-loop is used outside the for-loop scope;
it conflicts with the
declaration in the outer scope
definition of outer scope '__i' used
definition of for-loop scope '__i' ignored
And I confused with difference between MSDN words and actual results.
The MSDN says that in example above the first declaration of the
variable is not used,
but compiler says that for-loop scope variable is not used (and that is
true).
-------------------
Compiler Warning (level 1) C4288
nonstandard extension used : 'var' : loop control variable declared in
the for-loop is used
outside the for-loop scope; it conflicts with the declaration in the
outer scope
When compiling with /Ze, a variable declared in a for loop was used
after the for-loop scope.
A Microsoft extension to the C++ language allows this variable to remain
in scope, and
C4288 reminds you that the first declaration of the variable is not
used.
See /Zc:forScope for information about how to specify standard behavior
in for loops with /Ze.
The following sample generates C4288:
// C4288.cpp
// compile with: /W1 /c
int main()
{
int i = 0; // not used in this program
for (int i = 0 ; ; )
{
}
i++; // C4288, using for-loop declaration of i
}
-------------------
> > BTW in MSVC8 the "for loop scope" conformance and native wchar_t
> > supporting are enabled by default.
>
> You mean the default invocation of MSVC 8 enables these features?
Yes.
> That's good (but it still doesn't mean that we can assume
> they are always enabled since we have MSVC 7 to deal with).
Farid.