View Poll Results: In vc++, what do you set the for-loop var's scope to?

2. You may not vote on this poll
  • Enclose to inside the for-loop

    1 50.00%
  • Make local to block outside the for-loop.

    1 50.00%

Thread: visual c++ for loop var scope

  1. #1
    Registered User
    Join Date
    Jan 2002

    Question visual c++ for loop var scope

    Since the only compiler I have ever really used is visual c++, I used to think that it was part of the c++ standard for a variable declared within the initializer statement of a for-loop to have scope outside the for-loop. But I just started reading The C++ Programming Language recently and now I see that this is not the case. Actually, now I prefer to have the reduced scope, so I found the option to disable the setting in the compiler.

    But that got me wondering how many people conform to the vc++ default considering the compiler is very popular (at least from my pov)?

  2. #2
    In your face... ha ha ha Liger86's Avatar
    Join Date
    Dec 2002
    Motorcity Capital


    can you explain what you found out?

    I'm new to c++
    From Ukraine with love!

    Internationally known – widely respected

    - Digitally yourz -

  3. #3
    Registered User
    Join Date
    Jan 2002
    Sure, i'm no expert either, but i enjoy learning c++ (i'm going to college next year and i regret i may not get a chance to take many programming classes since i'll be going into engineering\physics).

    Anyway, the default setup in msoft visual c++ environment is to allow for code like this:
    for (int i = 0; i < 10; i++) {
    	// optional statements here.
    	// the variable 'i' can be used here.
    // the variable 'i' can be used here in visual c++.
    The "c++ standard" does not really allow the variable 'i' to be used outside the for-loop considering it was defined inside the for-loop's initializer sequance. I don't know how much of a beginner you are, but i hope that was adequate.

  4. #4
    Registered User
    Join Date
    Nov 2002
    I would like to hope anyone with some sense would follow The C++ Standard, but that might be alitlte bit too much to hope for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM