digitalmars.D.learn - function pointer and default argument
- Ellery Newcomer (9/9) Aug 22 2012 hey.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (9/18) Aug 22 2012 The type of the function pointer does not include the values of the
- Ellery Newcomer (3/19) Aug 22 2012 typeof lies.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/24) Aug 22 2012 Opened:
- Jonathan M Davis (7/19) Aug 22 2012 Default arguments are not part of the type. This behavior is very much o...
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
}
Aug 22 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
Aug 22 2012
On 08/22/2012 12:03 PM, Ali Çehreli wrote: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.typeof lies. pragma(msg, typeof(fn));void function(int i, double j = 1)
Aug 22 2012
On 08/22/2012 12:15 PM, Ellery Newcomer wrote:On 08/22/2012 12:03 PM, Ali Çehreli wrote:Opened: http://d.puremagic.com/issues/show_bug.cgi?id=8579 AliOn 08/22/2012 11:51 AM, Ellery Newcomer wrote:typeof lies. pragma(msg, typeof(fn)); > void function(int i, double j = 1)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.
Aug 22 2012
On Wednesday, August 22, 2012 11:51:45 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
}
Default arguments are not part of the type. This behavior is very much on
purpose.
http://d.puremagic.com/issues/show_bug.cgi?id=3866
http://d.puremagic.com/issues/show_bug.cgi?id=8402
http://d.puremagic.com/issues/show_bug.cgi?id=8515
- Jonathan M Davis
Aug 22 2012









=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> 