www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Native D functions & Assembler modules

reply Alexander Panek <alexander.panek brainsware.org> writes:
Hello,

I'm asking myself for a few days now if it'd be possible to call native 
D functions (without "extern(C)") directly out of an assembler module 
(compiled with nasm, for example). As far as I know D has a little 
different function naming convention than C, so it would be interesting 
if there's a static definition of how native functions are named.

I didn't find any information on the official D site, so I thought it'd 
be a good idea to ask in the newsgroup so Walter or some uber-mighty D 
coder could have a chance to answer.

Thanks in advance and regards,
Alex
Feb 16 2006
next sibling parent reply Sean Kelly <sean f4.ca> writes:
Alexander Panek wrote:
 Hello,
 
 I'm asking myself for a few days now if it'd be possible to call native 
 D functions (without "extern(C)") directly out of an assembler module 
 (compiled with nasm, for example). As far as I know D has a little 
 different function naming convention than C, so it would be interesting 
 if there's a static definition of how native functions are named.
In the same vein, it might be nice if we could forward-declare functions defined in other modules. Sean
Feb 16 2006
parent "Kris" <fu bar.com> writes:
I think you can, if you make them static class members <g>

class Utils
{
    static int myFunc(int);
    static bool myOtherFunc(int);
}


"Sean Kelly" <sean f4.ca> wrote in message 
news:dt2rug$1b1p$2 digitaldaemon.com...
 Alexander Panek wrote:
 Hello,

 I'm asking myself for a few days now if it'd be possible to call native D 
 functions (without "extern(C)") directly out of an assembler module 
 (compiled with nasm, for example). As far as I know D has a little 
 different function naming convention than C, so it would be interesting 
 if there's a static definition of how native functions are named.
In the same vein, it might be nice if we could forward-declare functions defined in other modules. Sean
Feb 16 2006
prev sibling next sibling parent "Walter Bright" <newshound digitalmars.com> writes:
"Alexander Panek" <alexander.panek brainsware.org> wrote in message 
news:dt2jtu$14qu$1 digitaldaemon.com...
 I'm asking myself for a few days now if it'd be possible to call native D 
 functions (without "extern(C)") directly out of an assembler module 
 (compiled with nasm, for example).
Sure. In order to see how to do it, call the function in D. Then, obj2asm the resulting .obj file, that'll tell you the name mangling and the calling convention.
Feb 16 2006
prev sibling parent Don Clugston <dac nospam.com.au> writes:
Alexander Panek wrote:
 Hello,
 
 I'm asking myself for a few days now if it'd be possible to call native 
 D functions (without "extern(C)") directly out of an assembler module 
 (compiled with nasm, for example). As far as I know D has a little 
 different function naming convention than C, so it would be interesting 
 if there's a static definition of how native functions are named.
import std.stdio; // put your function here... char [] f(int a, Whatever w) { } void main() { writefln( f.mangleof); }
 
 I didn't find any information on the official D site, so I thought it'd 
 be a good idea to ask in the newsgroup so Walter or some uber-mighty D 
 coder could have a chance to answer.
 
 Thanks in advance and regards,
 Alex
Feb 21 2006