How to create a function declaration?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Jan 12 11:07:49 PST 2007
Marcio Faustino wrote:
> 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)»
'printf' is problematic because object.d (which is automatically
imported into every D module) also declares it.
That code might otherwise compile, but I'm not sure what would happen at
the linking stage; printf is also defined in the C runtime library which
is linked to by default. It might just use one of the two, or it might fail.
More information about the Digitalmars-d-learn
mailing list