By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,221 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,221 IT Pros & Developers. It's quick & easy.

Strange VC 6.0 compiler problem

P: n/a

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
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Mark wrote:
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

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #2

P: n/a

"Mark" <ma**************@comcast.net> wrote in message
news:m8********************@comcast.com...

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....
}

}

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


Jul 23 '05 #3

P: n/a
Mark wrote:
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.
Jul 23 '05 #4

P: n/a
Mark wrote:
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.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5

P: n/a
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:1116743909.723652@athnrd02...
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.
--
Gary
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.