Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error C2086: 'i' : redefinition

696 views
Skip to first unread message

Firoz Nathani

unread,
Sep 12, 2000, 6:09:58 AM9/12/00
to

VC++ does not seem to comply to the c++ standard as if I have a code like

for(int i;;)
{
}

for(int i;;)
{
}

The compiler gives the following error error C2086: 'i' : redefinition.

Is ther any way to change this behaviour to the default C++ standard of the
scope of i being within the for block .

Thanks

Firoz


Viatly Nurkhatow

unread,
Sep 12, 2000, 9:14:27 AM9/12/00
to

you can (would) decalre i on the external level

example:
int i = 0;
for( i;;)
{
}

for(i;;)
{
}

Regards

Vitaly
www.chat.ru/~nurkht


Firoz Nathani <fi...@nathani.com> wrote in message
news:e1NhiDK...@cppssbbsa02.microsoft.com...

Joe Delekto

unread,
Sep 12, 2000, 9:07:16 AM9/12/00
to

Greets,

There is a way to do this with compiler option, however, you'll break
lots of things (like MFC and other supporting hosts) if you do such. There
are a few suggested workarounds for this that can be found in the VC++ FAQ:

http://www.mvps.org/vcfaq/lang/1.htm

Regards,

Joe

"Firoz Nathani" <fi...@nathani.com> wrote in message
news:e1NhiDK...@cppssbbsa02.microsoft.com...

Erik Funkenbusch

unread,
Sep 12, 2000, 12:38:31 PM9/12/00
to

First, VC++ 6 does not claim to be a standard conforming compiler. Second,
VC++ 6 was released at the same time the standard was ratified, which means
it was designed at least a year before so. Which means that it's pretty
much impossible for it to have been standard conforming (unless the
developers were psychic) even if they had wanted it to be.

This behavior, however, had changed several years earlier in the draft
standard, and VC++ does support it (in a very limited form) with the /Za
compiler switch. However, this switch is pretty much useless since it
disables all extensions, including those needed to compile most of the
standard headers (things like #pragmas and such are also turned off, thus
the headers won't compile).

You can easily work around this in a conformant way by placing extra braces
around your for statement:

{
for(int i...){};
}

Others will suggest using a #define which redefines 'for', which I would not
suggest. This can cause subtle side effects in existing code and can lead
to messy problems.

"Firoz Nathani" <fi...@nathani.com> wrote in message
news:e1NhiDK...@cppssbbsa02.microsoft.com...

Firoz Nathani

unread,
Sep 12, 2000, 12:40:21 PM9/12/00
to

Thanks Joe, your comments were very helpful

"Joe Delekto" <jdel...@netvillage.com> wrote in message
news:OmfessLHAHA.293@cppssbbsa04...

0 new messages