Strange VC 6.0 compiler problem

M

Mark

The following code works with gnu compilers (ISO compliant declaration of
the variable "i")

void foo()
{
for (int i = 0; i < length; i++) {
loop code....
}

for (int i = 0; i < length; i++) {
loop code....
}

}

However, the compiler in VC 6.0 complains:
error C2374 'i' : redefinition: multiple initialization...

What's up? Is there a switch I can set in the VC++ compiler to allow it to
accept these ISO compliant use if 'i'

Thanks in advance.
Mark
 
L

Larry I Smith

Mark said:
The following code works with gnu compilers (ISO compliant declaration of
the variable "i")

void foo()
{
for (int i = 0; i < length; i++) {
loop code....
}

for (int i = 0; i < length; i++) {
loop code....
}

}

However, the compiler in VC 6.0 complains:
error C2374 'i' : redefinition: multiple initialization...

What's up? Is there a switch I can set in the VC++ compiler to allow it to
accept these ISO compliant use if 'i'

Thanks in advance.
Mark

No. VC 6 predates some of the stds. It has the 'extension'
that once 'i' is defined it exists until the end of the function.

Larry
 
P

Peter Julian

Mark said:
The following code works with gnu compilers (ISO compliant declaration of
the variable "i")

void foo()
{
for (int i = 0; i < length; i++) {
loop code....
}

for (int i = 0; i < length; i++) {
loop code....
}

Unfortunately, VC6 doesn't comply to the standard in regards with the
lifetime of the loop's variable. You could change the identifier or reuse
the original:

for (i = 0; i < length; i++)
{
// 2nd loop code....
}

but thats non-comforming, not to mention ugly. A better solution (other than
changing compiler):

for (int j = 0; j < length; j++)
{
// 2nd loop code....
}
 
R

Ron Natalie

Mark said:
What's up? Is there a switch I can set in the VC++ compiler to allow it to
accept these ISO compliant use if 'i'
There is a switch, but if you turn it on NONE of the Microsnot runtime
icnludes will compile.

The easiest kludge is to do

#define for if(false)else for

early on in your files.
 
I

Ioannis Vranos

Mark said:
The following code works with gnu compilers (ISO compliant declaration of
the variable "i")

void foo()
{
for (int i = 0; i < length; i++) {
loop code....
}

for (int i = 0; i < length; i++) {
loop code....
}

}

However, the compiler in VC 6.0 complains:
error C2374 'i' : redefinition: multiple initialization...

What's up? Is there a switch I can set in the VC++ compiler to allow it to
accept these ISO compliant use if 'i'


VC++ 6 is ancient. Upgrade to VC++ 2003.

You can also download the command line compiler of VC++ 7.1 from Microsoft site for free
(named "Microsoft Visual C++ Toolkit 2003"). You can also download VC++ Express 2005 Beta
2 from there.
 
G

Gary Labowitz

Ioannis Vranos said:
VC++ 6 is ancient. Upgrade to VC++ 2003.

You can also download the command line compiler of VC++ 7.1 from Microsoft site for free
(named "Microsoft Visual C++ Toolkit 2003"). You can also download VC++ Express 2005 Beta
2 from there.

And there has been a fix for this on Dinkumware (I think) for years.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top