473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3814
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 error: Error 212: "small.cc", line 200 #...
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; ------------------------------- c = ( a == b );...
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 -- func_foo (){
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 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
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 Microsoft compiler everything is alright, but when I...
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 _MALLOCFREE_H_ #define _MALLOCFREE_H_ #define...
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. RL double d2030;
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 is happening myself. I am hoping that the problem...
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. -------------------- code -----------------------------------...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.