View mode: basic / threaded / horizontal-split · Log in · Help
May 25, 2007
Function Prototypes in D?
Hello everyone,

I'm a newcomer to the D language (though not new to programming) and currently reading through the documentation to learn this fascinating new language.

In any case, I was wondering -- does D make use of function prototypes like in C/C++? or are function definitions all that is necessary in D?

I did tried experimenting with the compiler and it appears that the answer to my question is the latter, but wanted to make sure this is indeed the case.

Thanks!
May 25, 2007
Re: Function Prototypes in D?
Joscci wrote:
> Hello everyone,
> 
> I'm a newcomer to the D language (though not new to programming) and currently reading through the documentation to learn this fascinating new language.
> 
> In any case, I was wondering -- does D make use of function prototypes like in C/C++? or are function definitions all that is necessary in D?
> 
> I did tried experimenting with the compiler and it appears that the answer to my question is the latter, but wanted to make sure this is indeed the case.

You can use prototypes if the implementation for a function is compiled 
separately, but you can't prototype a function that is later defined, 
and you can't provide multiple prototypes for the same function, even if 
they match exactly.  I've found this last restriction to be somewhat 
frustrating at times, as I believe it even applies to private prototypes.


Sean
May 25, 2007
Re: Function Prototypes in D?
Sean Kelly Wrote:

> Joscci wrote:
> > Hello everyone,
> > 
> > I'm a newcomer to the D language (though not new to programming) and currently reading through the documentation to learn this fascinating new language.
> > 
> > In any case, I was wondering -- does D make use of function prototypes like in C/C++? or are function definitions all that is necessary in D?
> > 
> > I did tried experimenting with the compiler and it appears that the answer to my question is the latter, but wanted to make sure this is indeed the case.
> 
> You can use prototypes if the implementation for a function is compiled 
> separately, but you can't prototype a function that is later defined, 
> and you can't provide multiple prototypes for the same function, even if 
> they match exactly.  I've found this last restriction to be somewhat 
> frustrating at times, as I believe it even applies to private prototypes.
> 
> 
> Sean

Gotcha.   Thanks for the clarification -- and for answering. :o)

- Joscci -
May 25, 2007
Re: Function Prototypes in D?
Reply to Joscci,

> Hello everyone,
> 
> I'm a newcomer to the D language (though not new to programming) and
> currently reading through the documentation to learn this fascinating
> new language.
> 
> In any case, I was wondering -- does D make use of function prototypes
> like in C/C++? or are function definitions all that is necessary in D?
> 
> I did tried experimenting with the compiler and it appears that the
> answer to my question is the latter, but wanted to make sure this is
> indeed the case.
> 
> Thanks!
> 

Prototypes can be used, but should only be used where the source is not available 
(closed source libs or cross language linking).
May 25, 2007
Re: Function Prototypes in D?
BCS Wrote:

> Reply to Joscci,
> 
> > Hello everyone,
> > 
> > I'm a newcomer to the D language (though not new to programming) and
> > currently reading through the documentation to learn this fascinating
> > new language.
> > 
> > In any case, I was wondering -- does D make use of function prototypes
> > like in C/C++? or are function definitions all that is necessary in D?
> > 
> > I did tried experimenting with the compiler and it appears that the
> > answer to my question is the latter, but wanted to make sure this is
> > indeed the case.
> > 
> > Thanks!
> > 
> 
> Prototypes can be used, but should only be used where the source is not available 
> (closed source libs or cross language linking).
> 
> 

Sweet.  Thanks for your input. :o)
Top | Discussion index | About this forum | D home