在“for”中声明的int var不是本地人? [英] int var declared in "for" not local?
问题描述
我的代码出现了一个奇怪的错误:
...
案例WM_COMMAND:
{
开关(LOWORD(wParam))//开关(控制ID)
{
...
case IDC_RAIN_ENABLE_SIMPLE:
{
if(BN_CLICKED == HIWORD(wParam))
{
for(int i = 0; i< 11; + i)
{
ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_SHOW);
}
for(int i = 11; i< 25; + i)// !!!错误!!!错误!!!
错误!!!
{
ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_HIDE);
}
}
休息;
}
...
休息;
}
...
休息;
}
...
休息;
...
我的编译器在工作中(MS VC ++ 6.0)标记在标记的行
" ERROR"以上。它说这是一个重新定义。我的。
怎么会这样?对于每个声明,我不是我的本地人吗?并不是
0到10的结束大括号。声明使我
超出范围?因此,在下一个声明中定义一个新的i
应该是完全可以的,不应该吗?
我在这里遗漏了什么,或者这是MS VC ++ 6.0中的一个错误?
-
困惑,
Robbie Hatley
孤独在pac bell dot net的狼intj
Robbie Hatley写道:我'这个代码出现了一个奇怪的错误:
......
案例WM_COMMAND:
{
开关(LOWORD(wParam))//开关(控件ID )
{
...
案件IDC_RAIN_ENABLE_SIMPLE:
{
if(BN_CLICKED == HIWORD(wParam))
{
for( int i = 0; i< 11; + i)
{ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_SHOW);
}
FO r(int i = 11;我< 25; + i)// !!!错误!!!错误!!!
错误!!!
{ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_HIDE);
}
}
休息;
}
...休息;
}
...
休息;
}
...
打破;
...
我的编译器在工作中(MS VC ++ 6.0)标记为错误的行。以上。它说这是一个重新定义。我是怎么回事?对于每个声明,我不是我的本地人吗?并不是0到10的结束大括号。声明使我
超出范围?所以在下一个声明中定义一个新的我应该是完全没问题的,不应该吗?
我在这里遗漏了什么,或者这是MS VC ++ 6.0中的一个错误?
它在VC ++ 6中是不可靠的。他们的标准解决方案是将
升级到VC.NET,这可能很昂贵或者否则,不需要,在一组花括号中包装
,这是丑陋的,或使用宏:
#define for if(0 );否则为
干杯! --M
" mlimber" <毫升***** @ gmail.com>在消息中写道
新闻:11 ********************* @ g43g2000cwa.googlegro ups.com ... < [...] ; ERROR"以上。它说这是一个重新定义。我是怎么回事?对于每个声明,我不是我的本地人吗? ...
它在VC ++ 6中是不可靠的。
我明白了!谢谢(你的)信息。看起来MS正在处理
var。 decls。对于parens。如果我没记错的话就像C的一些旧的一样,如果我没记错的话。
(这不就是K& RC这样做的吗?)我'' ll只需要
记住我的范围是封闭的封锁
for语句。
我想的方式我会处理就是这样:
case BLAT:
{
int i;
for(i = 0; i< 11; ++ i)
{
DoSomeStuff(Splat [i]);
}
for(i = 11; i< 25; ++ i)
{
DoOtherStuff(Splat [i]);
}
休息;
}
是的,有效。
-
干杯!
Robbie Hatley
孤独的狼inj at pac bell dot net
mlimber< ml ***** @ gmail.com>写道:
Robbie Hatley写道:for(int i = 0; i< 11; + i)
ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_SHOW);
}
for(int i = 11; i< 25; + i)// !!!错误!!!错误!!!
错误!!!
{ShowWindow(GetDlgItem(hDlg,RainControls [i]),SW_HIDE);
}
我的这里的编译器(MS VC ++ 6.0)在标记为ERROR的行上标记为ERROR。以上。它说这是一个重新定义。我是怎么回事?对于每个声明,我不是我的本地人吗?并不是0到10的结束大括号。声明使我
超出范围?所以在下一个声明中定义一个新的我应该是完全没问题的,不应该吗?
我在这里遗漏了什么,或者这是MS VC ++ 6.0中的一个错误?
这是VC ++ 6中的不合规。他们的标准解决方案是升级到VC.NET,这可能是昂贵的或其他不合需要的,以包装>对于一组花括号中的循环,这是丑陋的,或使用宏:
#define为if(0);否则为
此外,即使使用VC.NET 2003,您也必须将命令行选项
传递给编译器以强制执行此规则:
/ Zc: arg1 [,arg2] C ++语言一致性,其中参数可以是:
forScope - 为范围规则强制执行标准C ++
wchar_t - wchar_t是本机类型,而不是typedef
-
Marcus Kwok
I''m getting a bizarre error with this code:
...
case WM_COMMAND:
{
switch (LOWORD(wParam)) // switch (control ID)
{
...
case IDC_RAIN_ENABLE_SIMPLE:
{
if (BN_CLICKED == HIWORD(wParam))
{
for ( int i = 0 ; i < 11 ; +i)
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_SHOW);
}
for ( int i = 11 ; i < 25 ; +i) // !!! ERROR !!! ERROR !!!
ERROR !!!
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_HIDE);
}
}
break;
}
...
break;
}
...
break;
}
...
break;
...
My compiler here at work (MS VC++ 6.0) balks at the line marked
"ERROR" above. It says this is a "redefinition" of i .
How can this be? Isn''t i local to each for statement? Doesn''t
the closing curly brace of the "0 to 10" for statement make i
go out of scope? So defining a new i in the next for statement
should be perfectly ok, shouldn''t it?
Am I missing something here, or is this a bug in MS VC++ 6.0?
--
Puzzled,
Robbie Hatley
lone wolf intj at pac bell dot net
Robbie Hatley wrote:I''m getting a bizarre error with this code:
...
case WM_COMMAND:
{
switch (LOWORD(wParam)) // switch (control ID)
{
...
case IDC_RAIN_ENABLE_SIMPLE:
{
if (BN_CLICKED == HIWORD(wParam))
{
for ( int i = 0 ; i < 11 ; +i)
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_SHOW);
}
for ( int i = 11 ; i < 25 ; +i) // !!! ERROR !!! ERROR !!!
ERROR !!!
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_HIDE);
}
}
break;
}
...
break;
}
...
break;
}
...
break;
...
My compiler here at work (MS VC++ 6.0) balks at the line marked
"ERROR" above. It says this is a "redefinition" of i .
How can this be? Isn''t i local to each for statement? Doesn''t
the closing curly brace of the "0 to 10" for statement make i
go out of scope? So defining a new i in the next for statement
should be perfectly ok, shouldn''t it?
Am I missing something here, or is this a bug in MS VC++ 6.0?
It''s a non-conformancy in VC++ 6. Their standard solution is to upgrade
to VC.NET, which might be expensive or otherwise undesirable, to wrap
for loops in a set of curly braces, which is ugly, or to use a macro:
#define for if(0);else for
Cheers! --M
"mlimber" <ml*****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Robbie Hatley wrote:...
My compiler here at work (MS VC++ 6.0) balks at the line marked
"ERROR" above. It says this is a "redefinition" of i .
How can this be? Isn''t i local to each for statement? ...It''s a non-conformancy in VC++ 6.
I see! Thanks for the info. Looks like MS is handling
var. decls. in for parens. the same way as some old
implimentations of C did, if I remember correctly.
(Wasn''t this the way K&R C did it?) I''ll just have to
remember that the scope of i is the block ENCLOSING
the for statement.
I think the way I''ll handle that is like so:
case BLAT:
{
int i;
for ( i = 0; i < 11; ++i )
{
DoSomeStuff(Splat[i]);
}
for ( i = 11; i < 25; ++i )
{
DoOtherStuff(Splat[i]);
}
break;
}
Yes, that works.
--
Cheers!
Robbie Hatley
lone wolf intj at pac bell dot net
mlimber <ml*****@gmail.com> wrote:
Robbie Hatley wrote:for ( int i = 0 ; i < 11 ; +i)
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_SHOW);
}
for ( int i = 11 ; i < 25 ; +i) // !!! ERROR !!! ERROR !!!
ERROR !!!
{
ShowWindow(GetDlgItem(hDlg, RainControls[i]), SW_HIDE);
}
My compiler here at work (MS VC++ 6.0) balks at the line marked
"ERROR" above. It says this is a "redefinition" of i .
How can this be? Isn''t i local to each for statement? Doesn''t
the closing curly brace of the "0 to 10" for statement make i
go out of scope? So defining a new i in the next for statement
should be perfectly ok, shouldn''t it?
Am I missing something here, or is this a bug in MS VC++ 6.0?
It''s a non-conformancy in VC++ 6. Their standard solution is to upgrade
to VC.NET, which might be expensive or otherwise undesirable, to wrap
for loops in a set of curly braces, which is ugly, or to use a macro:
#define for if(0);else for
Additionally, even with VC.NET 2003, you must pass a commandline option
to the compiler to enforce this rule:
/Zc:arg1[,arg2] C++ language conformance, where arguments can be:
forScope - enforce Standard C++ for scoping rules
wchar_t - wchar_t is the native type, not a typedef
--
Marcus Kwok
这篇关于在“for”中声明的int var不是本地人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!