Visual Studio 2005 Express

Started by
18 comments, last by ravyne2001 18 years, 4 months ago
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.
Advertisement
What you are describing should never happen. Chances are, you have another error somewhere that's throwing you off.

CM
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.
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)?
Things change.
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.
Yes, 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 Mantear
Yes, 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 SiCrane
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.


Emphasis in bold -- ...How sure are you that you got the right version again? ([lol])
Things change.
Quote:Original post by Boku San
Emphasis 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.
Quote:Original post by Mantear
How 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.
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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement