Is there any good reason why C++ namespaces are "closed" in D?
Johannes Pfau
nospam at example.com
Thu Aug 2 06:03:53 UTC 2018
Am Wed, 01 Aug 2018 16:04:01 -0700 schrieb Walter Bright:
>
> Now, with D:
>
> extern (C++, ab) void foo(long);
> foo(0); // works!
> ---
> extern (C++, ab) void foo(long);
> extern (C++, ab) void foo(int); // error!
> ---
> extern (C++, ab) void foo(long);
> extern (C++, cd) void foo(int);
> foo(0); // error!
>
> I juxtaposed the lines so it's obvious. It's not so obvious when there's
> a thousand lines of code between each of those lines. It's even worse
> when foo(long) sends a birthday card to your daughter, and foo(int)
> launches nuclear missiles.
You probably didn't completely think this through: Earlier you suggested
to use aliases to avoid explicitly specifying the c++ scopes. Then you
suggested to use mixins or translator tools to automate alias generation
and avoiding manually writing that boiler plate code. But if you do that:
-------------------------
extern (C++, ab) void foo(long);
extern (C++, cd) void foo(int);
alias foo = ab.foo;
alias foo = cd.foo;
-------------------------
You've now got exactly the same problem with hijacking...
So the benefit of explicit c++ namespace scoping is only a benefit if you
do not use this alias trick. But then you face all other problems
mentioned earlier...
As a result, everybody now has to use the aliasing trick, the hijacking
problem still exists and we have to write lots of useless boilerplate.
--
Johannes
More information about the Digitalmars-d
mailing list