May 18, 2004 Linker error - function pointer | ||||
---|---|---|---|---|
| ||||
This works per documentation: void function(int) dg; void dothis(int x) { printf("%d\n", x); } void main(char[][] args) { dg = &dothis; dg(5); } However, if I put the declaration of dg in another file (test2.d in this case) I get: Error 42: Symbol undefined _D5test22dgPFiZv It works if I put test2.d in the build command line, but why is the linker looking for a function pointer? Thanks, Paul |
May 19, 2004 Re: Linker error - function pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Runde | Paul Runde wrote: > It works if I put test2.d in the build command line, but why is the linker looking for a function pointer? It's a piece of global data just like any other. It's equivalent to the C++: test.cpp: #include "test2.h" void dothis(int x) { printf("%d\n", x); } int main(char** args) { dg = &dothis; dg(5); } test2.cpp: void (*dg)(int); test2.h: extern void (*dg)(int); The difference is that D doesn't need a separate .h file. -- andy |
Copyright © 1999-2021 by the D Language Foundation