Function prototype: Difference between revisions

Added FreeBASIC
m (Omit Io)
(Added FreeBASIC)
Line 274:
 
void main() {}</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
' The position regarding prototypes is broadly similar to that of the C language in that functions,
' sub-routines or operators (unless they have already been fully defined) must be declared before they can be used.
' This is usually done near the top of a file or in a separate header file which is then 'included'.
 
' Parameter names are optional in declarations. When calling functions, using parameter names
' (as opposed to identifying arguments by position) is not supported.
 
Type MyType ' needed for operator declaration
i As Integer
End Type
 
Declare Function noArgs() As Integer ' function with no argument that returns an integer
Declare Function twoArgs(As Integer, As Integer) As Integer ' function with two arguments that returns an integer
Declare Function atLeastOneArg CDecl(As Integer, ...) As Integer ' one mandatory integer argument followed by varargs
Declare Function optionalArg(As Integer = 0) As Integer ' function with a (single) optional argument with default value
Declare Sub noArgs2() ' sub-routine with no argument
Declare Operator + (As MyType, As MyType) As MyType ' operator declaration (no hidden 'This' parameter for MyType)
 
 
' FreeBASIC also supports object-oriented programming and here all constructors, destructors,
' methods (function or sub), properties and operators (having a hidden 'This' parameter) must be
' declared within a user defined type and then defined afterwards.
 
 
Type MyType2
Public:
Declare Constructor(As Integer)
Declare Destructor()
Declare Sub MySub()
Declare Function MyFunction(As Integer) As Integer
Declare Property MyProperty As Integer
Declare Operator Cast() As String
Private:
i As Integer
End Type</lang>
 
=={{header|F Sharp|F#}}==
9,490

edits