function pointer and default argument

Ali Çehreli acehreli at yahoo.com
Wed Aug 22 12:03:19 PDT 2012


On 08/22/2012 11:51 AM, Ellery Newcomer wrote:
 > hey.
 >
 > is this valid code?
 >
 > void func1(int i, double j = 1.0) {
 > }
 >
 > void main() {
 > auto fn = &func1;
 > func1(1); //dmd: ok
 > fn(1); // dmd: not ok
 > }

The type of the function pointer does not include the values of the 
default parameters.

The type of fn is "a function taking int and a double, returning 
nothing". So the compiler must require that information at the call site.

The alternative could work too: The compiler could keep a table from 
function pointers to default parameters. But that would be slow.

I am not surprised by dmd's behavior.

Ali



More information about the Digitalmars-d-learn mailing list