Serving the Quantitative Finance Community

 
User avatar
audetto
Topic Author
Posts: 0
Joined: March 12th, 2002, 4:08 pm

neeeeed help

May 21st, 2002, 3:40 pm

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
 
User avatar
Onuk

neeeeed help

May 21st, 2002, 3:54 pm

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.
 
User avatar
softduck
Posts: 0
Joined: May 21st, 2002, 2:28 am

neeeeed help

May 21st, 2002, 8:57 pm

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.
 
User avatar
audetto
Topic Author
Posts: 0
Joined: March 12th, 2002, 4:08 pm

neeeeed help

May 22nd, 2002, 5:48 am

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.
 
User avatar
jamesbattle
Posts: 0
Joined: May 12th, 2002, 8:28 pm

neeeeed help

May 22nd, 2002, 8:39 am

Yep, your code is fine. It's a real shame, but the reality of C++ ...
 
User avatar
Ab
Posts: 1
Joined: March 27th, 2002, 11:15 am

neeeeed help

May 24th, 2002, 7:48 am

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