Re: scoping issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 4, 2008 at 09:33, Jason_Haynberg <haynberg@xxxxxxx> wrote:
> This strikes me as a bug.  What do you think?  It seems the first program should get the same error as the second?
>
>   for (int i = 0; i < 5; i++) {
>      cout << i << endl;
>      double i = 10.0;
>      cout << i << endl;
>   }
>

This is just intuition, but my understanding is that the double is
defined inside the for loop body block, and the int is defined outside
of it (it has to be, to persist its value), so there are 2 different
scopes, so it's not an error.

The analogous non-loop code would therefore be this, rather than what
you posted:

     int i = 0;
     {
          cout << i << endl;
          double i = 10.0;
          cout << i << endl;
     }

HTH,
~ Scott

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux