www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Function Prototypes in D?

reply Joscci <jsantos.uno.ceen gmail.com> writes:
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
next sibling parent reply Sean Kelly <sean f4.ca> writes:
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
parent Joscci <jsantos.uno.ceen gmail.com> writes:
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
prev sibling parent reply BCS <ao pathlink.com> writes:
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
parent Joscci <jsantos.uno.ceen gmail.com> writes:
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)
May 25 2007