How to create a function declaration?

Sean Kelly sean at f4.ca
Fri Jan 12 12:43:32 PST 2007


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.


Sean


More information about the Digitalmars-d-learn mailing list