How to create a function declaration?
Marcio Faustino
m.faustino.remove at gmail.com
Fri Jan 12 09:47:21 PST 2007
> 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.
> It's mostly useful to link to libraries designed to link to C, though
> Phobos also uses it in object.d to link to definitions in internal/object.d.
> It *could* also be useful to link to closed-source D libraries, but I
> haven't seen any yet...
So, how can I do something like this:
/*[ my_printf.d ]**************************************************************/
module my_printf;
extern (C) int printf(char* format, ...) {
return 0; // Just to test.
}
/******************************************************************************/
/*[ test.d ]*******************************************************************/
import my_printf;
void main() {
//printf("test\0"); // Error.
my_printf.printf("test\0"); // Ok.
}
/******************************************************************************/
Because the line with "Error" uncommented, the compiler says:
«test.d(5): Error: object.printf at /home/marcio/dmd/src/phobos/object.d(14)
conflicts with my_printf.printf at my_printf.d(3)»
More information about the Digitalmars-d-learn
mailing list