pragma(mangle)

Daniel Murphy yebblies at nospamgmail.com
Sat Jun 11 14:37:13 PDT 2011


"Nick Sabalausky" <a at a.a> wrote in message 
news:it0m05$6t7$1 at digitalmars.com...
>
> It sounds like it may have great potential for working around hashed 
> mangles. And maybe for exposing an API to another link-compatible language 
> like C (or not, I don't know, maybe extern(C) is always good enough for 
> that?).
>

You could use it, for example, to provide a function with C++ linkage taking 
a C++ long parameter, something which I think is currently impossible in D. 
D also can't provide C functions with names that are D reserved identifiers.

extern(C) pragma(mangle, "_pure")
void cpure() {}

> Two possible problems I can see:
>
> 1. Can it be reliably demangled? If not, I think that would severely 
> hinder its usefulness.
>
The idea is that you can support name mangling that the compiler can't 
understand.  I'd imagine you'd have to follow D name mangling if you wanted 
it demangled.

> 2. What if "myfunction" is templated?
>

Currently it attaches to one declaration and alters it's mangle, that's it. 
I'm not sure what should happen in more complicated situations.

I do think this should be possible:
template(name, T, U)
{
   extern pragma(mangle, genMangle!(name, T, U)
   void myfun(name, T, U);
} 




More information about the Digitalmars-d mailing list