From -3393620476734395369
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,22e67e794d61e771
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,22e67e794d61e771
X-Google-Attributes: gidf78e5,public
From: clamage@eng.sun.com (Steve Clamage)
Subject: Re: The definition of namespace.
Date: 1999/09/01
Message-ID: <7qjhvn$43r$1@engnews1.eng.sun.com>#1/1
X-Deja-AN: 519797356
X-NNTP-Posting-Host: taumet.eng.sun.com
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <37cbef06.0@newsfeed.jdedwards.com>
X-UID: 0000000001
X-Status: $$$T
Organization: Sun Microsystems Inc., Mountain View, CA
Newsgroups: comp.lang.c++,comp.std.c++
Originator: clamage@taumet


"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              ]




