Re: Why not add namespace feature into standard C?



<websnarf@xxxxxxxxx> wrote in message
news:1139247438.331814.142790@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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,

Widely requested.

the // comments,

Widely presumed to be already valid, thanks to C++.

complex numbers that are
incompatible with C++,

Which predate the C++ effort, so they're to blame for this one.

variable length arrays which are incompatible
with gcc,

Which has made next to no effort to do even the things required
by C99 that don't cause any backward compatability problems.

the "inline" placebo (register anyone?),

Also widely requested, and more than a placebo.

and an unqualified
"restrict" keyword.

Also requested by the vector processor folks, after they had
several years experience using it.

In short, I don't understand either.

No, I wouldn't expect you to.

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.)

And some subtle semantic implications that have yet to be worked out
completely in 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.

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.

And so long as you don't define a function or macro called swap,
or a macro called swaptemp, or a macro called tmp. Big win.

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.

Perhaps that's because you weren't there to guide us...

Remember that most C compiler
vendors today are also C++ vendors. So the compiler people already
know how to add namespaces into their compilers.

Well, yes, they just don't know exactly what semantics to ascribe
to them.

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: 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: vector of char arrays
    ... > components will really become part of the standard and if so, ... > the appropriate namespace. ... > 'tr1' may be a macro defined by users. ...
    (comp.lang.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) ... -- We in X3J11 knew that we had to add argument declarations to C, ... I think some features of C99 were a step too far and its wide-spread ...
    (comp.lang.c)