Jump to content
  • Advertisement
Sign in to follow this  
Mantear

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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])

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!