Re: Why not add namespace feature into standard C?
- From: "P.J. Plauger" <pjp@xxxxxxxxxxxxxx>
- Date: Mon, 6 Feb 2006 08:15:15 -0500
"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
.
- Follow-Ups:
- Re: Why not add namespace feature into standard C?
- From: WaterWalk
- Re: Why not add namespace feature into standard C?
- References:
- Why not add namespace feature into standard C?
- From: toolmaster
- Re: Why not add namespace feature into standard C?
- From: Nick Keighley
- Re: Why not add namespace feature into standard C?
- From: Keith Thompson
- Why not add namespace feature into standard C?
- Prev by Date: Re: Why not add namespace feature into standard C?
- Next by Date: Re: Why not add namespace feature into standard C?
- Previous by thread: Re: Why not add namespace feature into standard C?
- Next by thread: Re: Why not add namespace feature into standard C?
- Index(es):
Relevant Pages
|