digitalmars.D.learn - tyro[a.c.edwards]
What is the correct way to access externally defined variables and functions?
The following attempt result in a linker error.
Thanks,
Andrew
--------- test.d ----------
import std.cstream;
import std.process;
int global;
extern (D) void func();
void main() {
global = 12;
dout.writefln(global);
func();
dout.writefln(global);
}
--------- test2.d ----------
extern (D) int globe;
void func() {
globe = 47;
}
--------- result ----------
F:\did>dmd test test2
c:\dmd\bin\..\..\dm\bin\link.exe test+test2,,,user32+kernel32/noi;
OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
test.obj(test)
Error 42: Symbol Undefined _D4test4funcFZv
--- errorlevel 1
Jan 20 2006
"How to access externally defined varibles and functions?"
<How_member pathlink.com> wrote in message
news:dqrcnd$2n3s$1 digitaldaemon.com...
--------- test.d ----------
import std.cstream;
import std.process;
int global;
void main()
{
global = 12;
dout.writefln(global);
func();
dout.writefln(global);
}
--------- test2.d ----------
int globe;
void func()
{
globe = 47;
}
----------------------------
And are you trying to change "global" with "func()"?
Jan 20 2006
In article <dqrdqj$2o13$1 digitaldaemon.com>, Jarrett Billingsley says..."How to access externally defined varibles and functions?" <How_member pathlink.com> wrote in message news:dqrcnd$2n3s$1 digitaldaemon.com... --------- test.d ---------- import std.cstream; import std.process; int global; void main() { global = 12; dout.writefln(global); func(); dout.writefln(global); } --------- test2.d ---------- int globe; void func() { globe = 47; } ---------------------------- And are you trying to change "global" with "func()"?
Yes! I'm trying to access "global" from test.d with "func()". This solution doesn't really work for me. Basically, I have had the pleasure of using externally defined C functions and variables and would like to understand why they work and how to use that facility in D. Thanks again, Andrew
Jan 20 2006
What is the correct way to access externally defined variables and functions?
Simple: ########## test.d # module test; # # private import std.cstream; # private import std.process; # private import test2; # # public int global; # # void main () { # global = 12; # dout.writefln(global); # func(); # dout.writefln(global); # } ########## test2.d # module test2; # # private import test; # # void func () { # global = 47; // or // test.global = 47; # } -- Chris Sauls
Jan 20 2006









tyro[a.c.edwards] <tyro[a.c.edwards]_member pathlink.com> 