Cannot implicitly convert delegate to function

Lionello Lunesu lio at lunesu.remove.com
Thu Apr 27 06:55:15 PDT 2006


Hi,

Shouldn't a (pointer to a) function be convertible to a delegate? Seems 
to me it's like casting an int to a long; the latter has "more info" and 
can be converted back into the former without the loss of data. The same 
holds for function/delegate: a function could be converted to a delegate 
for "null"; by forgetting the "this" (null), we get the function pointer 
back.

#import std.format;
#void _disp_putc( dchar c ) {
#	int i = cast(int)c;
#	if (c >= 0x80)
#		i = '?';
#//	disp_putc(i);
#}
#void disp_writef(...) {
#	std.format.doFormat(&_disp_putc,_arguments,_argptr);
#}

Results in (v0.154):

 >dmd t.d
t.d(9): function std.format.doFormat (void 
delegate(dchar),TypeInfo[],void*) does not match argument types 
(void(*)(dchar c),TypeInfo[],void*)
t.d(9): cannot implicitly convert expression (& _disp_putc) of type 
void(*)(dchar c) to void delegate(dchar)


Right?

L.



More information about the Digitalmars-d-learn mailing list