www.digitalmars.com         C & C++   DMDScript  

D - user-defined attributes

reply "Pavel Minayev" <evilone omen.ru> writes:
Walter, is it possible to add user-defined attributes to
the language - something that would conform to this in C:

    #ifdef DLL
        #define MYEXPORT __stdcall _export
    #else
        #define MYEXPORT __cdecl
    #endif
    ...
    MYEXPORT void foo() { }

It could look like this:

    version (DLL)
        attribute MyExport = extern(Windows) export;
    else
        attribute MyExport = extern(D);
    ...
    attribute(MyExport) void foo() { }

Could be helpful in writing projects that can be either
static libs or DLLs, as well as porting such (zlib!) to
D.
Feb 08 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a41776$25eb$1 digitaldaemon.com...
 Walter, is it possible to add user-defined attributes to
 the language - something that would conform to this in C:

     #ifdef DLL
         #define MYEXPORT __stdcall _export
     #else
         #define MYEXPORT __cdecl
     #endif
     ...
     MYEXPORT void foo() { }

 It could look like this:

     version (DLL)
         attribute MyExport = extern(Windows) export;
     else
         attribute MyExport = extern(D);
     ...
     attribute(MyExport) void foo() { }

 Could be helpful in writing projects that can be either
 static libs or DLLs, as well as porting such (zlib!) to
 D.
Why would functions in a DLL need a different calling convention?
Feb 08 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a41imd$2pnk$2 digitaldaemon.com...

 Why would functions in a DLL need a different calling convention?
Because it might be called from languages other than D.
Feb 08 2002
parent "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a41jgh$2q47$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a41imd$2pnk$2 digitaldaemon.com...

 Why would functions in a DLL need a different calling convention?
Because it might be called from languages other than D.
You can always just leave it in the C or Windows calling convention.
Feb 08 2002