Re: Why not add namespace feature into standard C?



"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:lnk6c851ad.fsf@xxxxxxxxxxxxxxxxxx

"Nick Keighley" <nick_keighley_nospam@xxxxxxxxxxx> writes:
toolmas...@xxxxxxx wrote:
Since many of the modern computer languages have built-in namespace
features, I can't understand why not add this feature into standard C.
I've heard many people complain of the lacking of namespace in C. Of
course, namespace doesn't eliminate name polution, but it helps more
than just to put some prefix before a function name. Is it because
adding namespace will make C more complex or some other reasons?

If you didn't, it might be worth considering asking this question in
comp.c.std.
My (not particularly informed) opinion.follows.

1. anything from C++ I'd view... warily. C is not C++ nor should it be.

If I recall correctly, prototypes (added by the 1989 ANSI C standard)
were inspired by C++.

Not exactly:

-- We in X3J11 knew that we had to add argument declarations to C,
even before we knew anything about C++.

-- I had written a commercial C compiler in the mid 1970s that
had argument declarations as part of function declarations, so
we had prior art that we knew worked.

-- We saw no good reason to deviate in major ways from the C++
form, once we knew about it. But we still added ..., for varying
length argument lists, and the Miranda rule (suggested by Sam
Harbison) for reconciling the old declarations with the new.

All in all, the borrowing from C++ was incidental. In a similar
way, we knew we needed to add constant declarations. There was
no perceived reason not to use the keyword const, though we
changed its semantics in subtle ways.

2. contrai-wise, namespaces don't seem to be particularly OO or
strongly
C++ like.
3. adding *anything* to the standard is going make C more complex
4. I think some features of C99 were a step too far and its wide-spread
non-adoption indicates other people think the same. (I liked bool :-)
)

In my opinion, C++-style namespaces could be added to C without too
much difficulty, and without drastically increasing the complexity of
the language.

Yes and no. First of all, namespaces are poorly designed in C++ --
they fail to solve most of the problems advanced as justification
for adding namespaces to C++. Second, and IMO more important, they
do nothing to solve the much larger problem in C (and C++) of
controlling the scope of macro definitions. Since C does not have
user-defined overloading of operators or functions, we would at
least avoid the worst problems of namespaces in C++, which are
only partially mitigated by argument-dependent lookup.

On the other hand, any additional feature will make the
language more complex, and the line has to be drawn somewhere.

Indeed. For a time in the early 1990s, I proposed picking up a number
of the "simpler" C++ additions. In the end, the C committee roundly
defeated all such proposals (other than // comments). In hindsight,
I think the committee was absolutely right.

And of course backward compatibility could also be an issue. If the
language were being designed from scratch today with namespaces,
either the standard library declarations could be in a single
namespace, or each header could define its own namespace -- but if
namespaces were added today, existing code that refers directly to
declarations from the standard headers would still have to work.

We certainly wouldn't want to imitate the disastrous decision in
C++ of putting all existing headers in namespace std.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


.



Relevant Pages

  • Re: Why not add namespace feature into standard C?
    ... features, I can't understand why not add this feature into standard C. ... macro in a namespace safe way. ... because other languages are solving real problems in programming that C ...
    (comp.lang.c)
  • Re: Why not add namespace feature into standard C?
    ... features, I can't understand why not add this feature into standard C. ... compile time guarantee that a pointer is valid) are two "obvious" ... macro in a namespace safe way. ...
    (comp.lang.c)
  • Re: GCC
    ... That spec says what the names of the standard header ... It's important if you want to the use the namespace feature. ... what use is a compiler that does ...
    (Debian-User)
  • Re: Do you put functions in the global namespace? Other than main()
    ... namespace std or namespaces within namespace std unless otherwise ... A program may add template specializations for any standard ... partial) of a standard library template results in undefined behavior ... Everything was in an identifiable compartment, ...
    (comp.lang.cpp)
  • Re: Getting Started w/ Standard C++ in Microsoft VC++ 6.0?
    ... makes programming for the Windows API *much* easier than using the API ... subsystems and rewrite the "back end" system in standard C++. ... You don't have to write "using namespace std" anywhere. ... application" (in VC6) and the standard library will be available. ...
    (microsoft.public.vc.mfc)