Skip to content

Parameter Modes

Narta Xaymar Dirks edited this page Oct 28, 2026 · 1 revision

Parameter modes (In, Out, InOut)

In the originals every parameter is passed by value: the function gets a copy, and changing it never reaches the caller. BlitzLLVM keeps that as the default (In), and adds two words in front of a parameter name to hand values back to the caller.

Function Swap(InOut a:Int32, InOut b:Int32)
	Local t:Int32 = a
	a = b
	b = t
End Function

Function Split(value:Int32, Out high:Int32, Out low:Int32)
	high = value / 256
	low = value Mod 256
End Function

Local x:Int32 = 1, y:Int32 = 2
Swap x, y        ; x is 2, y is 1
Split 1000, x, y ; x is 3, y is 232

The three modes

Mode Starts with Written values reach the caller Must be written
In (default) the value of the caller no no
Out the default value of the type (0, 0.0, "", Null) yes yes, on every path (an error otherwise)
InOut the value of the caller yes should be (warning inout-parameter-unwritten, level 3)

All three can be read and written inside of the function, the word only decides what is passed along. Function Name(In a:Int32) is the same as Function Name(a:Int32). The words are only special in front of a parameter name, so In, Out and InOut can still be used as names of variables and parameters.

The values are copied back when the function returns, not while it runs, so a function that calls itself works on its own copy at every level, and the caller only sees the result at the end. If the same variable is given to two Out or InOut parameters, the last parameter wins.

What the caller can pass

Out and InOut need something to write to: a variable (local or global), an element of an array, or a field of an object. The compiler refuses a constant, a number, a string, a call or any other expression, a whole array, and a variable of another type than the parameter (Out x:Int32 does not take a Float32, as the value could not be stored back unchanged). In parameters accept everything they always did.

Strings are copied like everywhere else, objects are passed as the handle to the object, so an Out b.Box can be given a New Box and the caller has it afterwards.

Default values

A parameter with = value can be left out by the caller. For Out, the default is applied before the function body runs (so Out x:Int32 = 5 starts with 5, also when the caller passes a variable). For InOut, the default is used when the caller leaves the argument out; otherwise the function starts with the caller's value. A parameter that is left out has no variable to write back to, and the function just works on its own copy.

Writing on every path

An Out parameter has to be written before every Return and before the end of the function, or the compiler stops with an error naming the place. For InOut the same check is the warning inout-parameter-unwritten (-W3), reported once for every Return (or end of function) that leaves without writing. What counts as writing: an assignment, being the counter of a For, being the target of Read, or handing it to an Out or InOut parameter of another function. A path that ends the program (End) does not count, and writing only inside of one branch of an If without an Else (or a Select without Default, a While or a For, which may run zero times) does not either. Functions that use Goto or Gosub are not checked.

Function Clamp(Out result:Int32, value:Int32)
	If value > 10 Then
		result = 10
	EndIf
	; Error: 'result' is not written when value is 10 or less
End Function

Not available

.decls libraries (Userlibs) keep their own way of passing values and do not use these words. Void functions can use them like any other function.

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally