On 18.03.2014 02:15, Marco Leise wrote:
Am Mon, 17 Mar 2014 20:10:31 +0100
schrieb Rainer Schuetze <r.sagita...@gmx.de>:

In that specific case, why does this not work for you?:

nothrow extern(Windows) {
    HANDLE GetCurrentProcess();
}


The attributes sometimes need to be selected conditionally, e.g. when
building a library for static or dynamic linkage (at least on windows
where not everything is exported by default). Right now, you don't have
an alternative to code duplication or heavy use of string mixins.

Can we write this? It just came to my mind:

enum attribs = "nothrow extern(C):";

{
     mixin(attribs);
         HANDLE GetCurrentProcess();
}


Interesting idea, though it doesn't seem to work:

enum attribs = "nothrow extern(C):";

extern(D) { // some dummy attribute to make it parsable
    mixin(attribs);
        int GetCurrentProcess();
}

int main() nothrow // Error: function 'D main' is nothrow yet may throw
{
return GetCurrentProcess(); // Error: 'attr.GetCurrentProcess' is not nothrow
}

I guess this is by design, the mixin introduces declarations after the parser has already attached attributes to the non-mixin declarations.

Reply via email to