* 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?