How do I make an extern function?
Jonathan M Davis
jmdavisprog at gmail.com
Mon Jun 28 18:06:16 PDT 2010
On Monday, June 28, 2010 17:51:09 Simen kjaeraas wrote:
> ////////////////////
> module a;
>
> extern void foo( );
>
> void bar( ) {
> foo( );
> }
> ////////////////////
> module b;
>
> import std.stdio;
>
> void foo( ) {
> writeln( "Hi!" );
> }
> ////////////////////
>
> The above does not work (Error 42: Symbol Undefined _D1a3fooFZv). Adding
> extern to foo in module b changes nothing. extern( C ) works, but seems
> like a hack. Better ideas?
Um, extern isn't needed in D. All you need to do is make the function public and
then import the module. I would expect this to work:
////////////////////
module a;
import b;
void bar( ) {
foo( );
}
////////////////////
module b;
import std.stdio;
void foo( ) {
writeln( "Hi!" );
}
////////////////////
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list