strange behavior with pointers to function with default args

BCS BCS at pathlink.com
Tue Jun 13 10:27:09 PDT 2006


<code>
import std.stdio;

void foo (int i, int j = 7){writef("foo(%d,%d)\n",i,j);}
void bar (int i, int j = 6){writef("bar(%d,%d)\n",i,j);}

void foo (int i){assert(0);}
void bar (int i){assert(0);}

void main(char[][] argv)
{
	{
	auto fp = &bar;
	fp(1);
	fp = & foo;
	fp(1);
	}

	{
	auto fp = &foo;
	fp(1);
	fp = & bar;
	fp(1);
	}
}
</code>

Prints:

bar(1,6)
foo(1,6)
foo(1,6)
bar(1,6)

Reversing the two blocks gives:

foo(1,7)
bar(1,7)
bar(1,7)
foo(1,7)

Placing the asserted functions first causes asserts. (Known issue: #52)

Is this correct??



More information about the Digitalmars-d-bugs mailing list