Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Variable Scope

Variable Scope

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++visual-studiotestingbeta-testing
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gizzo
    wrote on last edited by
    #1

    Hi everyone! Revising some code I've found this: for(int i=0; i That caused an ASSERT(HowCanItBe) into my brain. If "i" is declared into the "for", how is possible to use it later? The code compile right, so Was I wrong thinking that "i" _is_declared_ into the "for"? Then, talking with the partners at work someone pointed out that in VS you can do it, but in C++Builder it wouldn't compile. The question is What is the standard? And how are declared that kinds of variables? And just testing I can do things like `for(int i=0; i<5; i++) { ... } i = 6; for(int i=7; i<8; i++) { ... }` :omg::wtf: what is the scope then? :doh: Thank you in advance. Regards.

    K O S 3 Replies Last reply
    0
    • G Gizzo

      Hi everyone! Revising some code I've found this: for(int i=0; i That caused an ASSERT(HowCanItBe) into my brain. If "i" is declared into the "for", how is possible to use it later? The code compile right, so Was I wrong thinking that "i" _is_declared_ into the "for"? Then, talking with the partners at work someone pointed out that in VS you can do it, but in C++Builder it wouldn't compile. The question is What is the standard? And how are declared that kinds of variables? And just testing I can do things like `for(int i=0; i<5; i++) { ... } i = 6; for(int i=7; i<8; i++) { ... }` :omg::wtf: what is the scope then? :doh: Thank you in advance. Regards.

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      I think the actual rule is that: for (int i = 0; i < 10; i++) { } //now i is invisible here. But in VC6 it is visible after the for (...) And I believe in VS .net compiler, they have complied with the standard and local variables are not visible outside anymore. this is this.

      1 Reply Last reply
      0
      • G Gizzo

        Hi everyone! Revising some code I've found this: for(int i=0; i That caused an ASSERT(HowCanItBe) into my brain. If "i" is declared into the "for", how is possible to use it later? The code compile right, so Was I wrong thinking that "i" _is_declared_ into the "for"? Then, talking with the partners at work someone pointed out that in VS you can do it, but in C++Builder it wouldn't compile. The question is What is the standard? And how are declared that kinds of variables? And just testing I can do things like `for(int i=0; i<5; i++) { ... } i = 6; for(int i=7; i<8; i++) { ... }` :omg::wtf: what is the scope then? :doh: Thank you in advance. Regards.

        O Offline
        O Offline
        Owner drawn
        wrote on last edited by
        #3

        Gizzo wrote:

        If "i" is declared into the "for", how is possible to use it later?

        In VS 2005 it's back to normal "i" won't be visible outside for

        --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

        1 Reply Last reply
        0
        • G Gizzo

          Hi everyone! Revising some code I've found this: for(int i=0; i That caused an ASSERT(HowCanItBe) into my brain. If "i" is declared into the "for", how is possible to use it later? The code compile right, so Was I wrong thinking that "i" _is_declared_ into the "for"? Then, talking with the partners at work someone pointed out that in VS you can do it, but in C++Builder it wouldn't compile. The question is What is the standard? And how are declared that kinds of variables? And just testing I can do things like `for(int i=0; i<5; i++) { ... } i = 6; for(int i=7; i<8; i++) { ... }` :omg::wtf: what is the scope then? :doh: Thank you in advance. Regards.

          S Offline
          S Offline
          sunit5
          wrote on last edited by
          #4

          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcrefzcforscope.asp :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups