Code fails with linker error. Why?
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Oct 4 03:50:50 PDT 2014
On Saturday, 4 October 2014 at 10:37:40 UTC, eles wrote:
> On Saturday, 4 October 2014 at 10:27:18 UTC, John Colvin wrote:
>> On Saturday, 4 October 2014 at 04:02:46 UTC, eles wrote:
>>> On Friday, 3 October 2014 at 15:47:33 UTC, John Colvin wrote:
>>>> On Friday, 3 October 2014 at 15:44:16 UTC, eles wrote:
>
>> So the compiler has no way of knowing whether you've forgotten
>> to include a definition, or whether it's simply sitting in
>> some other object file / library / whatever. The linker,
>> however, can know, hence the linker error.
>
> No "extern" required?...
nope, no extern required. The extern you are referring to is the
storage class http://dlang.org/declaration.html#extern and is for
variables.
> This seem to allow an entire class of problems, by linking
> against long-time forgotten functions...
It's the core functionality that allows you to link to a function
in a library without having the entire source available. You have
a declaration, but the implementation is in another object file /
library.
D is slightly tighter than C wrt all this. In C, you can just
call functions without even having a declaration, the compiler
will assume the argument types from what you passed in. A
forgotten #include and compiling without warnings = horrific bugs
in C. In D the declaration is required.
More information about the Digitalmars-d-learn
mailing list