CallFunctionFast and optional Parameters

Just starting out? Need help? Post your questions and find answers here.
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

CallFunctionFast and optional Parameters

Post 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
Give Up everything but trying!
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CallFunctionFast and optional Parameters

Post 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.
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Re: CallFunctionFast and optional Parameters

Post by Franky »

OK, sounds understandable.
Thanks for reply :D
Give Up everything but trying!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CallFunctionFast and optional Parameters

Post by ts-soft »

Use Prototypes, is more recommend and solve the problem :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: CallFunctionFast and optional Parameters

Post 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)

Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply