What to do about default function arguments

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 25 21:00:03 PDT 2012


On Wednesday, April 25, 2012 20:44:07 Walter Bright wrote:
> A subtle but nasty problem - are default arguments part of the type, or part
> of the declaration?
> 
>     See http://d.puremagic.com/issues/show_bug.cgi?id=3866
> 
> Currently, they are both, which leads to the nasty behavior in the bug
> report.
> 
> The problem centers around name mangling. If two types mangle the same, then
> they are the same type. But default arguments are not part of the mangled
> string. Hence the schizophrenic behavior.
> 
> But if we make default arguments solely a part of the function declaration,
> then function pointers (and delegates) cannot have default arguments. (And
> maybe this isn't a bad thing?)

Can function pointers have default arguments in C? Honestly, it strikes me as 
rather bizarre for them to have default arguments. I really don't think that 
they buy you much.

If you use the function or delegate immediately after declaring it (as is 
typically the case when they're nested), then you could have just just put the 
default argument in the function itself and not have it as a parameter. And if 
you're holding on to a function or delegate long term, you're almost certainly 
going to be using it generically, in which case I wouldn't expect a default 
argument to make sense there often either.

I'd vote to just disallow default arguments for function pointers and 
delegates.

- Jonathan M Davis


More information about the Digitalmars-d mailing list