Page 1 of 1

CallFunctionFast and optional Parameters

Posted: Tue Jan 08, 2013 3:22 pm
by Franky
Hi there,

Code: Select all

Procedure MyProc(Arg1.l,Arg2.l,Arg3.l=5)
  Debug Arg1
  Debug Arg2
  Debug Arg3
EndProcedure

Debug "Without 3rd Argument"
CallFunctionFast(@MyProc(),1,2)

Debug "With 3rd Argument"
CallFunctionFast(@MyProc(),1,2,9)

Debugs
Without 3rd Argument
1
2
2 ;<- Should be 5
With 3rd Argument
1
2
9
It got better in 5.1, but it's not yet correct. In 5.0, the function without that third parameter was called twice, than the program crashed.

Best regards

Franky

Re: CallFunctionFast and optional Parameters

Posted: Tue Jan 08, 2013 3:30 pm
by Fred
CallFunction() accept any pointer, it can't know than the called function has default argument. Default arguments are set when calling the function, not by the function itself. It's not a bug.

Re: CallFunctionFast and optional Parameters

Posted: Tue Jan 08, 2013 3:52 pm
by Franky
OK, sounds understandable.
Thanks for reply :D

Re: CallFunctionFast and optional Parameters

Posted: Tue Jan 08, 2013 4:00 pm
by ts-soft
Use Prototypes, is more recommend and solve the problem :wink:

Re: CallFunctionFast and optional Parameters

Posted: Tue Jan 08, 2013 8:07 pm
by idle

Code: Select all

Prototype pMyProc(Arg1.l,Arg2.l,Arg3.l=5)

Procedure MyProc(Arg1.l,Arg2.l,Arg3.l)
  Debug Arg1
  Debug Arg2
  Debug Arg3
EndProcedure

Global pMyProc.pMyProc
pMyProc = @MyProc() 

Debug "Without 3rd Argument"
pMyProc(1,2)

Debug "With 3rd Argument"
pMyProc(1,2,9)