Page 1 of 1

neeeeed help

Posted: May 21st, 2002, 3:40 pm
by audetto
I've just started to use MSVC 6.0 and I already hate it!Why I cannot compile?for (int i = 0; i<5; i++) ;for (int i = 0; i<5; i++) ;The compiler tells me that "i" is already defined (in the second "for").......!!!!!!!!!!!!!!!! why?????????????????????byethanks

neeeeed help

Posted: May 21st, 2002, 3:54 pm
by Onuk
Audetto >> neeeeed helpNo, Visual C++ 6.0 needs help (and IMHO not the kind of help you might get from Visual Hash C .NOT 17.5).Irritating isn't it? As for why, there's a long and a short answer. The short one you know, and as for the long one the mind boggles.

neeeeed help

Posted: May 21st, 2002, 8:57 pm
by softduck
That's very strange indeed since that piece of code compiles fine under Sun Workshop's forte 6.1 compiler...and is perfectly valid too.

neeeeed help

Posted: May 22nd, 2002, 5:48 am
by audetto
Sorry, I should have read the help as soon as I had the problem...I was using Borland C Free Compiler where this code was perfectly legal, ... unfortunatlly MSVC doesn't allow this contruct: the scope of the first "int i" declaration is not only the "for {...}" stantment, but the whole function (or {....}) where it is.

neeeeed help

Posted: May 22nd, 2002, 8:39 am
by jamesbattle
Yep, your code is fine. It's a real shame, but the reality of C++ ...

neeeeed help

Posted: May 24th, 2002, 7:48 am
by Ab
for (int i = 0; i<5; i++) ;for (int i = 0; i<5; i++) ;The compiler tells me that "i" is already defined (in the second "for").......!!!!!!!!!!!!!!!! why?????????????????????The compiler is right, I don't see any pb in that. You typed "int i", this means you declared a variable named i of type int (the compiler will reserve a memory cell to it), then next line you declare a new variable of type int but with the same name as an existing one!!!for (int i=0;.....for (int j=0;....>>Good and will compile-----------------------------int i;for (i=0;.....for (i=0;....>>Not good but will compile-----------------------------for (int i=0;.....for (int i=0;....>>Will not compileHope this helps.Ab