How to create a function declaration?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Jan 12 14:03:40 PST 2007


Sean Kelly wrote:
> Frits van Bommel wrote:
>>
>> You're writing forward declarations. Seriously, D doesn't need them; 
>> forward references are allowed ;).
>>
>> A function declaration without definition is for when you put the 
>> definition in a different file, not to put it later in the same file.
> 
> I think the same conflict can occur in this situation though:
> 
>     module a;
> 
>     extern (C) void fn();
> 
>     module b;
> 
>     extern (C) void fn();
> 
>     module c;
> 
>     import a, b;
> 
>     void main()
>     {
>         fn();
>     }
> 
> This one has bitten me a few times where I had declared the prototype 
> for a C library routine to avoid importing the entire header module, and 
> a derived module imported both my module and the C header module.  Even 
> worse, the same error will occur if one of the two declarations is 
> private, because of how symbol resolution is handled.  This makes the 
> approach outlined above completely intractable, and actually more 
> restrictive than C where multiple prototypes of the same function are 
> allowed.

You cut that quote a bit short. Reread the rest of that paragraph at the 
end of your quote.
What I was talking about was more in the line of Phobos' object.d & 
internal/object.d, or a C source file and its D import module.
Either way, only one of the files is intended to be imported (but 
shouldn't get compiled itself). The other file then gets compiled and 
linked in its place.


More information about the Digitalmars-d-learn mailing list