function check(integer first, integer second, integer third) {
// expect: first == 1, second == 2, third == 3
}
control {
check(1, 2, 3);
}
```
```ttcn3 example="named mapping and evaluation order"
function next(inout integer n) return integer {
n := n + 1;
return n;
}
function check(integer first, integer second, integer third) {
log(first, second, third); // logs 2, 1, 3
}
control {
var integer n := 0;
check(second := next(n), first := next(n), third := next(n));
// The expressions are evaluated in textual order, not formal-parameter order.
}
```
```ttcn3 example="mixed mapping and evaluation order"
function next(inout integer n) return integer {
n := n + 1;
return n;
}
function check(integer first, integer second, integer third) {
log(first, second, third); // logs 1, 3, 2
}
control {
var integer n := 0;
check(next(n), third := next(n), second := next(n));
// The positional entry maps first; named entries map and run as written.
}
```
```ttcn3 example="invalid duplicate mapping"
function f(integer p, integer q) {}
control {
f(1, p := 2); // error: p is mapped twice
f(p := 1, p := 2); // error: p is mapped twice
}
```
```ttcn3 example="invalid named and missing mappings"
function f(integer p, integer q) {}
control {
f(p := 1, unknown := 2); // error: unknown is not a formal parameter
f(p := 1); // error: required formal parameter q is not mapped
}
```
```ttcn3 example="invalid omission of required parameter"
function f(integer required) {}
control {
f(-); // error: required is neither default nor variadic
}
```
```ttcn3 example="evaluation in caller scope"
const integer offset := 1;
function add(integer value) return integer {
const integer offset := 100;
return value;
}
control {
var integer base := 2;
var integer result := add(base + offset);
log(result); // logs 3, because offset is resolved in the caller's scope
}
```
- 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
```ttcn3 example="omitted empty actual parameter list"
template integer one() := 1;
template integer alsoOne := one; // equivalent to one()
```
> TODO: Check 5.4.2.m aliasing (of structs and unions) in the same function is forbidden (can we actually enforce that?)
```ttcn3 example="in parameter uses a compatible copy"
type integer Small (0..10);
function changeCopy(in integer p) {
p := 9;
}
control {
var Small n := 2;
changeCopy(n); // Small is compatible with integer
log(n); // logs 2: p has distinct storage
}
```
```ttcn3 example="each invocation has its own parameter copy"
function fibonacci(in integer n) return integer {
if (n < 2) {
return 1;
}
return fibonacci(n - 2) + fibonacci(n - 1);
}
control {
var integer result := fibonacci(2);
log(result); // logs 2
}
```
```ttcn3 example="out parameter copies its final value back"
type integer Small (0..10);
function produce(out integer p) {
p := 7;
}
control {
var Small result := 0;
produce(result);
log(result); // logs 7: compatible types need not be identical
}
```
```ttcn3 example="inout parameter is implicitly dereferenced"
function increment(inout integer p) {
p := p + 1;
log(p); // logs 2 through the binding to n
}
control {
var integer n := 1;
increment(n);
log(n); // logs 2
}
```
```ttcn3 example="invalid compatible but non-identical inout type"
type integer Small (0..10);
function increment(inout integer p) {
p := p + 1;
}
control {
var Small n := 1;
increment(n); // error: compatible types are not sufficient for inout
}
```
```ttcn3 example="invalid non-lvalue actual parameters"
const integer fixed := 0;
template integer pattern := 1;
function setOut(out integer p) {
p := 1;
}
function setInout(inout integer p) {
p := 1;
}
control {
setOut(0); // error: a literal is not a writable location
setInout(1 + 2); // error: an expression result is not a writable location
setOut(fixed); // error: a constant is not writable
setOut(pattern); // error: a template value is not a writable value
}
```
```ttcn3 example="invalid incompatible in and out types"
function consume(in integer p) {
}
function produce(out integer p) {
p := 1;
}
control {
var charstring text := "x";
consume(text); // error: charstring is not compatible with integer
produce(text); // error: integer cannot be copied back to charstring
}
```
```ttcn3 example="structured element passed by reference"
type record Pair {
integer left,
integer right
}
function increment(inout integer p) {
p := p + 1;
}
control {
var Pair pair := { left := 1, right := 2 };
increment(pair.left);
log(pair); // logs { left := 2, right := 2 }
}
```
```ttcn3 example="structured element receives out copy-back"
type record Pair {
integer left,
integer right
}
function produce(out integer p) {
p := 7;
}
**Examples**
```ttcn3 example="each parameter only once"
external function f(in integer p1, in integer p2 := 99);
control {
var Pair pair := { left := 1, right := 2 };
produce(pair.right);
log(pair); // logs { left := 1, right := 7 }
f(1, p1:= 2); // error
}
```
```ttcn3 example="structured template element passed by reference"
type record Pair {
integer left,
integer right
}
function replace(inout template integer p) {
p := 3;
}
```ttcn3 example="non left-hand-side value"
external function f(inout integer p1);
control {
var template Pair pattern := { left := 1, right := ? };
replace(pattern.left);
log(pattern); // logs { left := 3, right := ? }
}
```
```ttcn3 example="unintended side effects"
type component C {
var integer cVar;
}
function f(inout integer p) runs on C {
cVar := 10;
p := 99; // changing p also changes cVar, because both are
// references to the same piece of data.
log(cVar); // expected output: 99
}
testcase tc() runs on C {
f(cVar);
f(bit2int('1100101')); // error: reference to temporary value
}
```
@@ -667,6 +310,11 @@ variadic-parameter rules.
**Examples**
```
f(1, -) // the same
f(1)
```
```ttcn3 example="default omission and dash marker"
function report(integer value, integer base := 10, integer width := 2) {