Public Group

# Visual Studio 2005 Express

This topic is 4616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I downloaded VS 2005 Express today. I figured it was about time to give version 6 the boot. I'm getting used to the way things work in it, and ran across an odd thing. I've been using CodeWright to edit my files, which lets me easily comment out sections of code using '//' instead of '/* ... */'. However, the VS 2005 compiler seems to not like that. It seems to think the block of comments is the start of a new function, making my local variables undeclared. Anyone know a way around this? Thanks.

##### Share on other sites
What you are describing should never happen. Chances are, you have another error somewhere that's throwing you off.

CM

##### Share on other sites
Well, it appears that it doesn't like
for (int i = 0; i < some_num; i++){ ... }for (i = 0; i < some_num2; i++){ ... }
It wants me to re-declare 'i' for the second for loop. Is this because it is more strictly compliant, or is this something MS dreamed up? I haven't seen another C++ complain about it.

##### Share on other sites
That's an MS quirk -- you're using '05, right? I'd thought they'd have this cleared up by now.

You'll need to redeclare i in that for loop again -- I saw a workaround for it on flipcode, but, as we all know...that place is dead now. You can still search for it, if you like, it detailed a total replacement for for as a macro, which worked properly.

EDIT: Found the link to the article -- like SiCrane mentions below, I had thought this problem had been fixed. Workaround is here if you need it -- but, again, are you SURE you're using MSVC8 ('05)?

##### Share on other sites
According to standard C++, variables declared in for loops go out of scope when the for loop ends. MSVC 6 was broken with respect to this. MSVC 8 does it correctly.

##### Share on other sites

I'm somewhat surprised that the 'old way' is wrong. I've used a few other compilers (Green Hills, Code Composer, Visual DSP), and they all accepted the single declaration. How do most people handle their for-loop variables? Declare them at the top, ala C style? Or re-declare them each time?

##### Share on other sites
Quote:
 Original post by MantearYes, I'm using '05. Just downloaded and installed it.I'm somewhat surprised that the 'old way' is wrong. I've used a few other compilers (Green Hills, Code Composer, Visual DSP), and they all accepted the single declaration. How do most people handle their for-loop variables? Declare them at the top, ala C style? Or re-declare them each time?

Quote:
 Original post by SiCraneAccording to standard C++, variables declared in for loops go out of scope when the for loop ends. MSVC 6 was broken with respect to this. MSVC 8 does it correctly.

Emphasis in bold -- ...How sure are you that you got the right version again? ([lol])

##### Share on other sites
Quote:
 Original post by Boku SanEmphasis in bold -- ...How sure are you that you got the right version again? ([lol])

Yes... I am sure. The old way let you declare a variable in a for-loop statement, and you no longer had to declare it again even for a for-loop that came after the previous one. That's how MSVC 6 did it, that's how the other compilers I've used have done it. That's against the standard that SiCrane stated. MSVC 8 does it correctly, in other words, I need to re-declare the variable if I want to use it in the next for-loop. I'm not sure what your point was.

##### Share on other sites
Quote:
 Original post by MantearHow do most people handle their for-loop variables? Declare them at the top, ala C style? Or re-declare them each time?

I declare them for each for-loop almost always. I figure compilers should be smart enough (at least smarter than me) to be able to optimize things best. This is just me though, and I'm definitely not a consumate (but I am proficient) C++ programmer.

##### Share on other sites
The quick solution:

Go to Project->Properties
Configuration Properties
C/C++
Language

Set "Force Conformance In For Loop Scope" to "No"

However, it'd be better to fix up your for loops.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×