简体   繁体   中英

Anonymous struct inside loop

The code below compiles fine with g++

#include <iostream>
using namespace std; 

int main() 
{
    for (struct { int i; double j; } x = {0,0};  x.i < 10; ++x.i, x.j+=.1)
    {
        std::cout << x.i << " " << x.j << '\n';
    }
}

But with MSVC2005 I get errors

error C2332: 'struct' : missing tag name
error C2143: syntax error : missing ')' before '{'
warning C4094: untagged 'struct' declared no symbols
error C2059: syntax error : 'empty declaration'
error C2143: syntax error : missing ';' before ')'
error C2143: syntax error : missing ';' before ')'
error C2065: 'x' : undeclared identifier
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1>        type is ''unknown-type''
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1>        type is ''unknown-type''

I want to know if anonymous struct inside loops are an "extension" or a language feature and MSC2005 is missing it?

It's a bug in msvc . Unfortunately, it is not high in their priority list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM