Re: Why not add namespace feature into standard C?



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/

.



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. ... macro in a namespace safe way. ... And so long as you don't define a function or macro called swap, ...
    (comp.lang.c)
  • Re: C++ error "System.FormatException"
    ... No one will be able to compile your code, ... What is namespace "System"? ... standardized by the C++ language is the std namespace. ... At last, standard C++ data types, char and double! ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Why not add namespace feature into standard C?
    ... I've heard many people complain of the lacking of namespace in C. ... prototypes (added by the 1989 ANSI C standard) ... I think some features of C99 were a step too far and its wide-spread ... language more complex, and the line has to be drawn somewhere. ...
    (comp.lang.c)
  • Re: C Programming: A Modern Approach 2nd Edition
    ... I don't know enough about the survey or about C++ compiler ... a number of C99 features either have not been implemented at ... significant is whether they're needed by the code you need to compile. ... Compare this to the general level of conformance to the C90 standard, ...
    (comp.lang.c)