Optional Arguments

General FreeBASIC programming questions.
Post Reply
Michael
Posts: 61
Joined: Jul 15, 2005 21:11
Location: Oregon, USA
Contact:

Optional Arguments

Post by Michael »

It would appear that if I set the default of an argument in a method, then passing it a value is optional. Is this supposed to happen? I can call the following w/o any arguments.

Observe:

Code: Select all

sub TGtkApplication.MessageBox( byref title as string = "Message", byref text as string = "" )

    var msgdlg = gtk_message_dialog_new_with_markup( 0, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "" )

    gtk_window_set_title(GTK_WINDOW(msgdlg), title)
    gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(msgdlg), text)

    gtk_dialog_run(GTK_DIALOG(msgdlg))
    gtk_widget_destroy(GTK_WIDGET(msgdlg))

end sub
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Post by KristopherWindsor »

Yes, this is the purpose of specifying values for arguments.
Because values can be omitted, these calls may be valid:

mysub(1)
mysub(1, 2)
mysub(, 2)
mysub()
mysub(,, 3)

You have specified defaults in case the values are not given in the call.
Typically, the more optional (less important) parameters are listed last, so you won't see things like "mysub(,, 3)" much.
Post Reply