472,328 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Strange VC 6.0 compiler problem


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
5 3735
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

"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Peng | last post by:
Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an...
5
by: sriram | last post by:
I have the following: class BSA { ... ... ... ... public: enum VRGAttrId {
8
by: Harvey Twyman | last post by:
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller. Code Extract: ------------------------------- char a,b,c;...
1
by: Rahul Iyer | last post by:
G'day I have encountered quite a strange problem with a new function i've added to an existing software. Pseudo code of actions. -- begins...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file...
6
by: markus.litz | last post by:
Hello, I have a strange problem with some of my c++ code. I have a normal for- loop like this for(int i = 1; ..... on MS-Windows with a...
5
by: profjwang | last post by:
the problem is in some strange for me, the program's goal will realize my own malloc and free function, the project's h_file below: #ifndef...
1
by: raylopez99 | last post by:
The below did not set off my compiler, perhaps because I set the warnings to a higher (less nag) level. Strange. FYI, no question being asked....
18
by: Eric | last post by:
Ok...this seems to be treading into some really esoteric areas of c++. I will do my best to explain this issue, but I don't fully understand what...
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. ...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.