Is there any good reason why C++ namespaces are "closed" in D?
Walter Bright
newshound2 at digitalmars.com
Thu Aug 2 08:59:56 UTC 2018
On 8/1/2018 11:08 PM, Manu wrote:
> I think implementing the string alternative is the only robust way
> forward, because that also solves the additional problem of being able
> to name C++ namespaces that are invalid D keywords, which has bitten
> me in at least 2 particularly noteworthy occasions.
Which keywords were those?
In any case, this is a general problem when dealing with C and C++
interoperability, and your solution would only deal with one case of it. For
example,
--- C++ ---
void with();
int scope;
enum pure;
-----------
If this problem were to be solved, it should be solved, not hacked for one case
only. There are many ways of dealing with it:
1. pragma(mangle)
2. change the names in the C/C++ side
3. use a macro -Dwith=with_ when compiling the C/C++ code
4. write wrappers/forwarders/trampolines in C/C++, compile them and link them in
5. write a tool that patches the object file (not as hard as it sounds, the
symbol table is usually in one spot, but of course the patcher would have to be
implemented for each object file format). I've written object file patchers
before, they work surprisingly well. Nobody else does it, presumably because the
thought inspires terror :-)
6. provide some switch to the D compiler to rename A=>B in the object file
symbols, though I'd worry such would slow the compiler down
7. perhaps amend the language such that an identifier of the form "__keyword"
would appear in the object file as "keyword".
More information about the Digitalmars-d
mailing list