Topic: The definition of namespace.
Author: Ron Natalie <ron@sensor.com>
Date: 1999/09/01 Raw View
Jerry wrote:
>
> Hi:
> I feel that the namespace and scope are almost the same thing. So I give
> the definition of namespace as the name of a scope. Is it a correct
> definition? Thanks in advacne.
>
In C++ "namespace" is a very specific concept. It refers to a facility
to partition global names.
Scope is a broader concept. It describes how a name is interpretted
at a give point. It involves the function block heirarchy, the
class heirarcy, and the namespaces in use.
---
[ 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: clamage@eng.sun.com (Steve Clamage)
Date: 1999/09/02 Raw View
"George Policello" <news.@digisoftinc.com> writes:
>I wouldn't define namespace as scope. A namespace defines a scope, but it
>is really a declarative region, like a class.
The C++ standard says in section 3.3:
"Every name is introduced in some portion of 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."
Seems to me a namespace is a declarative region.
--
Steve Clamage, stephen.clamage@sun.com
[ 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: Waranun Bunjongsat <bunjonwa@trek.CS.ORST.EDU>
Date: 1999/09/01 Raw View
On 31 Aug 1999, Jerry wrote:
>
> Hi:
> I feel that the namespace and scope are almost the same thing. So I give
> the definition of namespace as the name of a scope. Is it a correct
> definition? Thanks in advacne.
I don't think so. You can't do this, for example ...
{
class a {...};
class b {...};
int func1(...){...};
int x;
char y;
}
You can't define a scope this way. A scope has to be in a smaller
unit than a function.
At the same time, you can't define a namespace inside a function.
I would rather say namespace is a way to help largescale programming more
organized. It's similar to package in Java. Namespace is introduced
because using include files alone is not enough to make the
growing amount of code in a software project organized.
Regards,
Waranun,
[ 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: "George Policello" <news.@digisoftinc.com>
Date: 1999/09/01 Raw View
I wouldn't define namespace as scope. A namespace defines a scope, but it
is really a declarative region, like a class.
- George
Jerry <jerrydung@yahoo.com> wrote in message
news:37cbef06.0@newsfeed.jdedwards.com...
>
> Hi:
> I feel that the namespace and scope are almost the same thing. So I
give
> the definition of namespace as the name of a scope. Is it a correct
> definition? Thanks in advacne.
>
> jerry
>
> jerrydung@yahoo.com
>
>
>
>
> [ 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 ]
>
---
[ 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: clamage@eng.sun.com (Steve Clamage)
Date: 1999/09/01 Raw View
"Jerry" <jerrydung@yahoo.com> writes:
> I feel that the namespace and scope are almost the same thing. So I give
>the definition of namespace as the name of a scope. Is it a correct
>definition? Thanks in advacne.
A namespace defines a scope, but not all scopes have all the
properties of namespaces. Unlike other scopes, a namespace
can be reopened and added to. Names from namespaces can be
imported selectively or accessed en masse in other scopes.
You can do that to a limited extent with class scopes, but not
at all with other kinds of scopes.
In addition, not all namespaces have names. The global namespace
has no name (it's considered a namespace to make other parts of
the language definition easier to specify). You can declare
unnamed namespaces. An unnamed namespace has a name, but you
cannot write it.
Finally, there are other kinds of scopes that are unlike namespaces.
To pick one example, a block scope in a function can contain
statements directly; a namespace cannot.
So, yes, except for the quirks of the global namespace and
unnnamed namespaces, a namespace names a scope. But "namespace"
and "scope" are not the same thing. Namespaces were introduced
into C++ because the existing scope rules were deemed inadequate
to handle large (or even medium-large) programs.
--
Steve Clamage, stephen.clamage@sun.com
[ 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: "Michael VanLoon" <michaelv@edifecs.com>
Date: 1999/09/01 Raw View
Jerry <jerrydung@yahoo.com> wrote in message
news:37cbef06.0@newsfeed.jdedwards.com...
>
> Hi:
> I feel that the namespace and scope are almost the same thing. So
I give
> the definition of namespace as the name of a scope. Is it a correct
> definition? Thanks in advacne.
There are plenty of C++ books what will teach exactly what a namespace
is and how to use it. See the FAQ for a complete list.
One suggestion: The C++ Programming Language, Third Edition; Bjarne
Stroustrup.
---
[ 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: "Jerry" <jerrydung@yahoo.com>
Date: 1999/08/31 Raw View
Hi:
I feel that the namespace and scope are almost the same thing. So I give
the definition of namespace as the name of a scope. Is it a correct
definition? Thanks in advacne.
jerry
jerrydung@yahoo.com
[ 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 ]