How to create a function declaration?

Sean Kelly sean at f4.ca
Fri Jan 12 08:53:07 PST 2007


Marcio Faustino wrote:
> Hi everyone,
> 
> How can I create a function declaration only and provide its definition later?
> For example:
> 
> /******************************************************************************/
> extern (C) int print(char*);
> 
> extern (C) int print(char* s) {
>     return printf("%s", s);
> }
> 
> void main() {
>     print(cast(char*) "test\0");
> }
> /******************************************************************************/
> 
> The compiler says:
> «test.d(9): function test.print called with argument types:
>         (char*)
> matches both:
>         test.print(char*)
> and:
>         test.print(char*)»
> 
> What am I doing wrong?
> Thanks,

Nothing.  I think the implementation needs to be in a separate file if 
you want separate compilation like that.  Though it would admittedly be 
nice if the compiler could recognize that there is no actual conflict 
between a declaration and an implementation of the same function.


Sean


More information about the Digitalmars-d-learn mailing list