473,387 Members | 3,810 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,387 software developers and data experts.

Another strange compile error with visual studio c++ 6.0

Is there a problem with the declaration of the y-variable in the for loop?
I'm not sure about the break, (if it should be there or not since I didn't
write the original code), but the error: "initialization of y is skipped by
case label" was reported.

int main(){
int x[10];
int a=4;
switch (a){
case 1: for (int y=0;y<10;y++) x[y]=y; break;
case 2: a=5;
}
}

Thanks,
Gunnar.
Oct 20 '05 #1
5 1890
Simple: The C++ implementation in VS6 C++
doesn't allow var-declarations in for-parantheses!
Mind:It's an old compiler, from the mid-late 90s !
Wasn't FULLY compliant with C++ standards.

"Gunnar G" <de****@comhem.se> schrieb im Newsbeitrag
news:Ww*********************@newsc.telia.net...
Is there a problem with the declaration of the y-variable in the for loop?
I'm not sure about the break, (if it should be there or not since I didn't
write the original code), but the error: "initialization of y is skipped
by
case label" was reported.

int main(){
int x[10];
int a=4;
switch (a){
case 1: for (int y=0;y<10;y++) x[y]=y; break;
case 2: a=5;
}
}

Thanks,
Gunnar.

Oct 20 '05 #2
* Gunnar G:
Is there a problem with the declaration of the y-variable in the for loop?
I'm not sure about the break, (if it should be there or not since I didn't
write the original code), but the error: "initialization of y is skipped by
case label" was reported.

int main(){
int x[10];
int a=4;
switch (a){
case 1: for (int y=0;y<10;y++) x[y]=y; break;
case 2: a=5;
}
}


MSVC 6.0 followed the pre-standard rules where the scope of y didn't end with
the loop, but extended to the end of the block the loop is placed in (and
that's still the default in MSVC 7.1, which is the one I use). With this
non-standard treatment y can be access in case 2, without having been
initialized. The problem is not with the declaration but with the compiler
using old rules where the scope of y extends a bit too far.

Try a more modern -- or less antiquated ;-) -- compiler.

For Microsoft's, add the necessary compiler options to get near standard
behavior (turning on exception handling, RTTI, for-loop conformance etc.).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 20 '05 #3

"Jens Marder" <fc**********@yahoo.com> wrote in message
news:43**********@x-privat.org...
Simple: The C++ implementation in VS6 C++
doesn't allow var-declarations in for-parantheses!
Not true. (However it does get scoping rules wrong).
Mind:It's an old compiler, from the mid-late 90s !
Wasn't FULLY compliant with C++ standards.
That's true, but nothing to do with OP's problem.

"Gunnar G" <de****@comhem.se> schrieb im Newsbeitrag
news:Ww*********************@newsc.telia.net...
Is there a problem with the declaration of the y-variable in the for
loop?
I'm not sure about the break, (if it should be there or not since I
didn't
write the original code), but the error: "initialization of y is skipped
by
case label" was reported.
Gunnar: Did you look up the error in the help file?
It explains what you did wrong.

-Mike

int main(){
int x[10];
int a=4;
switch (a){
case 1: for (int y=0;y<10;y++) x[y]=y; break;
case 2: a=5;
}
}

Thanks,
Gunnar.


Oct 20 '05 #4
> Gunnar: Did you look up the error in the help file?
It explains what you did wrong.

I regret to say "no", since the problem was only presented to me by someone
that I thought would have looked there.
But I'll have a look there as soon as I can.
Thanks for answering..
Oct 20 '05 #5
"Gunnar G" <de****@comhem.se> wrote in message
news:Ww*********************@newsc.telia.net...
Is there a problem with the declaration of the y-variable in the for loop?
I'm not sure about the break, (if it should be there or not since I didn't
write the original code), but the error: "initialization of y is skipped
by
case label" was reported.

int main(){
int x[10];
int a=4;
switch (a){
case 1: for (int y=0;y<10;y++) x[y]=y; break;
case 2: a=5;
}
}

Thanks,
Gunnar.


It's just M$ VC being stupid. The same thing would happen if it wasn't
initialized in a for statement. The compiler is presuming (wrongly in this
case) that you want to use y outside the case statement. Simple solution,
put the code in brackets and it'll be happy.

case 1: { for (int y=0;y<10;y++) x[y]=y; break; };
case 2: { a=5; } // Brackets not needed here.

This just lets the compiler know that teh scope of y is within the case
statement only.
Oct 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Brian | last post by:
Greetings: I am trying to compile the following code via command line. It compiles just fine in visual studio 2002 v7 so i took looked at the properties and i got the following command line...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
3
by: Andrew Luke | last post by:
Hi all you C++ guru's! I'm 'very, very' new to C++ and I'm having a little trouble configuring my VS environment I think - when I try and compile some sample code I'm getting the following...
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
0
by: JW | last post by:
I'm using MSVC7.0 and I'm getting a ton of errors with most of them occurring in cstdio. Any thoughts as to what might cause this? d:\Program Files\Microsoft Visual Studio .NET\Vc7...
2
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project...
1
by: hansolox1 | last post by:
The following program simply sets the icon of a form called form1. When I get the name of the embedded icon using GetManifestResourceNames(), I store the name in a string variable called s. The...
1
by: stromhau | last post by:
Ok, i have a file with main and an additional .cpp file i include in the main file but i get a lot of strange warnings when including. Both files compile just great separately. It seems that it have...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.