Re: Why not add namespace feature into standard C?
- From: websnarf@xxxxxxxxx
- Date: 6 Feb 2006 09:37:18 -0800
toolmaster@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.
Because the standards people were more concerned with adding arbitrary
declaration positioning, the // comments, complex numbers that are
incompatible with C++, variable length arrays which are incompatible
with gcc, the "inline" placebo (register anyone?), and an unqualified
"restrict" keyword. In short, I don't understand either.
Namespaces and parameter references (which essentially provides a
compile time guarantee that a pointer is valid) are two "obvious"
features from C++ that would be a good thing to add to C (since they
have nothing to do with OO programming, and have obvious value.)
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.
Actually its a *critical* problem with C. Trying implementing a swap
macro in a namespace safe way. The best you can do is to have an
obfuscated symbol prefix. With namespaces you can at least do the
following:
namespace swaptemp;
#define swap(x,y,type) {
type swaptemp::tmp = (x);
(x) = (y);
(y) = swaptemp::tmp;
}
So as long as people stay away from the "swaptemp" namespace, this will
work regardless of what variable name is chosen for x or y.
Is it because adding namespace will make C more complex or some
other reasons?
I think its just misplaced priorities. The C standards people *DID*
add a lot of things into the C99 standard (including some C++ things)
-- they just picked the *wrong* things. Remember that most C compiler
vendors today are also C++ vendors. So the compiler people already
know how to add namespaces into their compilers.
--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
.
- Follow-Ups:
- Re: Why not add namespace feature into standard C?
- From: Mark McIntyre
- Re: Why not add namespace feature into standard C?
- From: P.J. Plauger
- Re: Why not add namespace feature into standard C?
- From: websnarf
- Re: Why not add namespace feature into standard C?
- References:
- Why not add namespace feature into standard C?
- From: toolmaster
- Why not add namespace feature into standard C?
- Prev by Date: Re: Unix I/O and C library I/O, why there are two sets of I/O functions?
- 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
|