Bug 14176 – the code has a link problem.

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-02-13T19:07:00Z
Last change time
2017-06-26T01:10:48Z
Assigned to
nobody
Creator
steven_kladitis

Comments

Comment #0 by steven_kladitis — 2015-02-13T19:07:11Z
import std.stdio; import std.traits; int foo(int x, long y); void Bar(R, P...)(R function(P)) { writeln("return type is ", typeid(R)); writeln("parameter types are ", typeid(P)); } void main() { Bar(&foo); } // compiles but does not link in windows
Comment #1 by steven_kladitis — 2015-02-13T19:07:38Z
the code came the tuple page on this web site.
Comment #2 by steven_kladitis — 2015-02-13T23:26:31Z
this is using dmd 2.066.1 for windows
Comment #3 by k.hara.pg — 2015-02-14T15:36:46Z
(In reply to steven kladitis from comment #0) > import std.stdio; > import std.traits; > > int foo(int x, long y); > > void Bar(R, P...)(R function(P)) > { > writeln("return type is ", typeid(R)); > writeln("parameter types are ", typeid(P)); > } > > void main() > { > Bar(&foo); > } > > > // compiles but does not link in windows A function pointer &foo should point actual function body code. But foo does not have body. Therefore it fails to link. Supplying body code to foo will fix the issue. int foo(int x, long y) { return 0; }
Comment #4 by k.hara.pg — 2015-02-14T15:41:10Z
(In reply to steven kladitis from comment #1) > the code came the tuple page on this web site. Note that, D supports separate compilation model. `int foo(int x, int y);` is a function declaration without its definition (== function body code), similar to: // A C lib function declaration extern(C) int printf(const char* fmt, ...); So it's not a mistake in the example code is.
Comment #5 by steven_kladitis — 2015-02-14T17:30:00Z
Thanks, I am trying to learn D. :) Trying examples to see what they do.
Comment #6 by dlang-bugzilla — 2017-06-26T01:10:48Z
Closing as per Kenji's explanation.