- expand values according to right-hand-side-semantics ([assignment])
- out:
- _pass by value_ (copy, type compatibility)
- copy back when changed
- expand values according to left-hand-side-semantics ([assignment])
- inout:
- _pass by reference_ (type equality required, strong typing)
- expand values according to left-hand-side-semantics ([assignment])
**Restrictions**
- Passing references of fields or elements and references to the container in the same actual parameter list is forbidden; to prevent aliasing related issues.
- values that that cannot be used on the left-hand-side of an assignment, must also be `in
- empty parameter list may be omitted for parameterized object that are not functions, testcase, altstep, external functions
> TODO: Check 5.4.2.m aliasing (of structs and unions) in the same function is forbidden (can we actually enforce that?)
**Examples**
```ttcn3 example="each parameter only once"
external function f(in integer p1, in integer p2 := 99);
control {
f(1, p1:= 2); // error
}
```
```ttcn3 example="non left-hand-side value"
external function f(inout integer p1);
control {
f(bit2int('1100101')); // error: reference to temporary value
}
```
### Default parameters
A _default parameter_ is an `in` formal value or template parameter whose
declaration includes a default value or default template assignment.
**Syntactical Description**
A default parameter is a `FormalPar` whose `DefaultAssignment` is present in
the shared [formal-parameter syntax](#formal-parameters). `:= Expr` declares a
default value and `:= TemplateInstance` declares a default template. The
assignment is part of the formal parameter declaration and is not an actual
parameter assignment. `TemplateType` includes any template restriction
declared for the formal template parameter.
**Semantic description**
The declared default value or template shall be used when no actual parameter
maps to the default parameter. In list notation, `-` shall also select the
declared default for the formal parameter at that position. In assignment
notation, the default shall be selected by omitting an assignment for that
formal parameter; `-` shall not be used as the right-hand side of an actual
parameter assignment.
In list notation, a default parameter may be omitted without `-` only when no
actual parameter follows it. Thus, omission without a marker applies to a
trailing sequence of default, `out`, or variadic formal parameters. Assignment
notation may omit any default parameter by name irrespective of its position.
Explicit actual parameter expressions shall first be evaluated in their
textual order as specified in [actual parameters](#actual-parameters). The
default expressions and template instances selected by omission or `-` shall
then be evaluated in formal-parameter order. A default expression or template
instance shall be evaluated in the scope of the parameterized entity, not in
the caller's scope.
The resulting default value or template shall be assigned to distinct storage
for the formal parameter using the same compatibility and assignment rules as
an explicit actual value or template for an `in` parameter.
For a [variadic parameter](#variadic-parameters) with a declared default,
omission or `-` shall select that default. Without a declared default, omission
or `-` shall produce the empty `record of` value or template specified by the
variadic-parameter rules.
**Restrictions**
1. Only an `in` formal parameter may declare a default value or template.
2. A default expression or template instance shall be compatible with the
formal parameter's type. A default template shall also satisfy the template
restriction of its formal parameter.
3. A default expression or template instance shall be well-defined at entry to
the scope of the parameterized entity and shall not refer to another formal
parameter in the same formal parameter list.
4. A default value of component type shall be `null`, `mtc`, `self`, or
`system`. A default template for component type shall be built from these
special values.
5. A default value of port, timer, or `default` type shall be `null`.
6. Functions used while evaluating a default value or template should avoid
side effects.
**Examples**
```
f(1, -) // the same
f(1)
```
```ttcn3 example="default omission and dash marker"
function report(integer value, integer base := 10, integer width := 2) {
log(value, base, width);
}
control {
report(7); // base == 10, width == 2
report(7, -, 4); // base == 10, width == 4
report(value := 7, width := 4); // base == 10
}
```
```ttcn3 example="default template omission"
function matches(template integer expected := ?) {
// ...
}
control {
matches(); // expected uses the default template ?
matches(-); // expected uses the default template ?
}
```
```ttcn3 example="default evaluation order and scope"
const integer fallback := 1;
external function mark(charstring event) return integer;
function observe(integer first := mark("first"),
integer second := mark("second"),
integer third := fallback) {
log(first, second);
}
control {
const integer fallback := 99;
observe(second := mark("explicit"));
// mark is called for "explicit" first and "first" second.
// third uses the module-scope fallback value 1, not the caller's 99.
}
```
```ttcn3 example="invalid default declarations and omissions"
function badOut(out integer p := 1) {} // error: only in may have a default
function badInout(inout integer p := 1) {} // error: only in may have a default
function badType(integer p := "one") {} // error: incompatible default