Topic: Declarative regions


Author: nimel@hem1.passagen.se
Date: 1999/04/13
Raw View
In article <370E067E.9BC9CE41@wizard.net>,
  James Kuyper <kuyper@wizard.net> wrote:

> No. It starts as soon as 'i' is declared; it doesn't wait for the call
> to g().

I agree with this interpretation. But what about the following code?

int main()
{
  int i; // What is the declarative region of this variable?
  i = 42;
  {
    int i;
    i = 0x42;
  }
  i = 042;
}

/Niklas Mellin


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "AllanW {formerly AllanW@my-dejanews.com}" <allan_w@my-dejanews.com>
Date: 1999/04/13
Raw View
In article <923635828.788.79@news.remarQ.com>,
  "PM" <pmucci@innova.net> wrote:
> 3.3 Declarative regions and scopes
>
> Every name is introduced in some portion of the program text called a
> declarative
> region, which is the largest part of the program in which that name is
> valid, that is,
> in which that name may be used as an unqualified name to refer to the same
> entity....
>
> Ok, what has me confused is the "largest part of the program"

They couldn't just say "in the function where it is declared" because
that isn't always accurate.

    namespace xxx {
        const int myint = 25; // xxx::myint d.r. begins here
        int j = myint - 5;    // Uses xxx::myint
      // xxx::myint d.r. ends at this curly brace:
    }

    int main() {
        const int myint = 21; // First local myint d.r. begins here
        {
            const int myint = 0; // Second local myint d.r. begins here
            // Note that first local myint d.r. excludes second's d.r.
            // because they have the same name.
            cout << "Myint is " << myint << endl;
          // Second local myint d.r. ends at this curly brace:
        }
        // We're still(again) in first local myint's d.r.
        cout << "Myint is " << myint << endl;
      // First local myint d.r. ends at this curly brace:
    }

> As I understand it, a declarative region is a property of a name.  Because
> its side effect is:
>
>  "in which that name may be used as an unqualified name to refer to that
> same entity".

Exactly. It's easier to understand than it is to read the nitty-gritty.
When you look at the code above, you probably have no trouble figuring
out which times the token "myint" means 25, which times it means 21,
and which times it means 0. That's all that this section of the standard
is trying to tell you.

Notice that we can't say that the declarative region extends to the
end of the function. First, it might not be in a function. Second, if
it is inside a block statement in the function, then it ends only
to the end of the block, not to the end of the whole function.

----
Allan_W@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: James.Kanze@dresdner-bank.com
Date: 1999/04/13
Raw View
In article <370dff31.27375854@news>,
  wduminy@bigfoot.com (Willem D) wrote:
> Hi,
> This is the way I understand it.
>
> Simply put, the region of a variable (eg. my_var) can be verified by
> prefixing every line (or statement) in the region with:
> cout << my_var;
>
> Assuming that the operator is available, every line of code that can
> compile could be included in the declarative region of my_var.
>
> The declaritive region the the largest consecutive set of lines that
> can compile.

Declaritive regions don't have to be consecutive.  If you introduce a
declaration of the same name in a nested scope, it suspends the initial
declaration until the new name goes out of scope.

--
James Kanze                         mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orient=E9e objet/
                        Beratung in objekt orientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany  Tel. +49 (069) 63 19 86 =
27

-----------=3D=3D Posted via Deja News, The Discussion Network =3D=3D----=
------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own  =
 =20
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "PM" <pmucci@innova.net>
Date: 1999/04/09
Raw View
3.3 Declarative regions and scopes

Every name is introduced in some portion of the program text called a
declarative
region, which is the largest part of the program in which that name is
valid, that is,
in which that name may be used as an unqualified name to refer to the same
entity....


Ok, what has me confused is the "largest part of the program"

As I understand it, a declarative region is a property of a name.  Because
its side effect is:

 "in which that name may be used as an unqualified name to refer to that
same entity".
(So there must be at least one Declarative region per name)

Now here is where I get confused, what is the "largest part of the program"
requirement ?

for example

void f ();
void g ();

int main ()
  {
    int i; // The name i is introduced.
    f ();  // inside of f () main's i will not be in a declarative region

    g ();  // main's i doesn't require qualification here
    g ();
    return 0;
  }

void f ()
  {
    int i;
    // lots of stuff ...
  }

void g ()
  {
    // lots of stuff ...
  }

when I look at the code above, to me - it looks like the "largest part of
the program"
where I can refer to the name 'i' in main, unqualified would be everything
starting
at the first call to g ().

Now, I think I am missing something because its seems odd that
a name's declarative region can be separated from its introduction into
the translation unit.

Help is appreciated, thanks !
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: wduminy@bigfoot.com (Willem D)
Date: 1999/04/11
Raw View
Hi,
This is the way I understand it.

Simply put, the region of a variable (eg. my_var) can be verified by
prefixing every line (or statement) in the region with:
cout << my_var;

Assuming that the operator is available, every line of code that can
compile could be included in the declarative region of my_var.

The declaritive region the the largest consecutive set of lines that
can compile.

Hope it helps.

On 09 Apr 99 06:47:49 GMT, "PM" <pmucci@innova.net> wrote:

>3.3 Declarative regions and scopes
>
>Every name is introduced in some portion of the program text called a
>declarative
>region, which is the largest part of the program in which that name is
>valid, that is,
>in which that name may be used as an unqualified name to refer to the same
>entity....
>
>
>Ok, what has me confused is the "largest part of the program"
>
>As I understand it, a declarative region is a property of a name.  Because
>its side effect is:
>
> "in which that name may be used as an unqualified name to refer to that
>same entity".
>(So there must be at least one Declarative region per name)
>
>Now here is where I get confused, what is the "largest part of the program"
>requirement ?
>
>for example
>
>void f ();
>void g ();
>
>int main ()
>  {
>    int i; // The name i is introduced.
----FROM HERE
>    f ();  // inside of f () main's i will not be in a declarative region
>
>    g ();  // main's i doesn't require qualification here
>    g ();
>    return 0;
----TO HERE
>  }
>
>void f ()
>  {
>    int i;
-- THIS i is a SEPERATE ENTITY
>    // lots of stuff ...
>  }
>
>void g ()
>  {
>    // lots of stuff ...
>  }
>
>when I look at the code above, to me - it looks like the "largest part of
>the program"
>where I can refer to the name 'i' in main, unqualified would be everything
>starting
>at the first call to g ().
>
>Now, I think I am missing something because its seems odd that
>a name's declarative region can be separated from its introduction into
>the translation unit.
>
>Help is appreciated, thanks !
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: James Kuyper <kuyper@wizard.net>
Date: 1999/04/11
Raw View
PM wrote:
>
> 3.3 Declarative regions and scopes
>
> Every name is introduced in some portion of the program text called a
> declarative
> region, which is the largest part of the program in which that name is
> valid, that is,
> in which that name may be used as an unqualified name to refer to the same
> entity....
>
> Ok, what has me confused is the "largest part of the program"
>
> As I understand it, a declarative region is a property of a name.  Because
> its side effect is:
>
>  "in which that name may be used as an unqualified name to refer to that
> same entity".
> (So there must be at least one Declarative region per name)
>
> Now here is where I get confused, what is the "largest part of the program"
> requirement ?
>
> for example
>
> void f ();
> void g ();
>
> int main ()
>   {
>     int i; // The name i is introduced.

This is the start of declarative region for main()'s 'i'.

>     f ();  // inside of f () main's i will not be in a declarative region

True, but nothing written on that line is inside of f(). We're still in
main() at this point, so the we're still in the declarative region of
main()'s 'i'. If you had declared 'f' as "void f(int);" then f(i) would
be legal, and the 'i' would refer to main()'s 'i', not to f()'s.

>     g ();  // main's i doesn't require qualification here
>     g ();
>     return 0;

end of declarative region

>   }
>
> void f ()
>   {
>     int i;
>     // lots of stuff ...
>   }
>
> void g ()
>   {
>     // lots of stuff ...
>   }
>
> when I look at the code above, to me - it looks like the "largest part of
> the program"
> where I can refer to the name 'i' in main, unqualified would be everything
> starting
> at the first call to g ().

No. It starts as soon as 'i' is declared; it doesn't wait for the call
to g().

> Now, I think I am missing something because its seems odd that
> a name's declarative region can be separated from its introduction into
> the translation unit.

It's not.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]