Update page 'Aer v1.0 Specification'
@@ -252,17 +252,9 @@ An example:
|
|||||||
int $integer = 7 + (int) $str; // contains value: 52
|
int $integer = 7 + (int) $str; // contains value: 52
|
||||||
|
|
||||||
### 5.14. References
|
### 5.14. References
|
||||||
References in Aer are a means to access the same variable content by different names. They are not like C pointers; for instance, they does not allow to perform pointer arithmetic using them, they are not actual memory addresses, and so on. Instead, they are symbol table aliases. There are three basic operations performed using references: assigning by reference, passing by reference, and returning by reference.
|
References in Aer are a means to access the same variable content by different names. They are not like C pointers; for instance, they does not allow to perform pointer arithmetic using them, they are not actual memory addresses, and so on. Instead, they are symbol table aliases. There are two basic operations performed using references: passing by reference and returning by reference.
|
||||||
|
|
||||||
#### 5.14.1. Assign By Reference
|
#### 5.14.1. Return Reference
|
||||||
In the first of these, Aer references allow to make two variables refer to the same content.
|
|
||||||
|
|
||||||
int &$a, $b;
|
|
||||||
$a = $b;
|
|
||||||
|
|
||||||
It means that $a and $b point to the same content.
|
|
||||||
|
|
||||||
#### 5.14.2. Return Reference
|
|
||||||
When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement.
|
When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement.
|
||||||
|
|
||||||
int[] $table = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
|
int[] $table = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
|
||||||
@@ -271,7 +263,7 @@ When a function returns a reference, it returns an implicit pointer to its retur
|
|||||||
return $table[$i]; // returns a reference to the ith element
|
return $table[$i]; // returns a reference to the ith element
|
||||||
}
|
}
|
||||||
|
|
||||||
#### 5.14.3. Pass By Reference
|
#### 5.14.2. Pass By Reference
|
||||||
This is done by making a local variable in a function and a variable in the calling scope referencing the same content.
|
This is done by making a local variable in a function and a variable in the calling scope referencing the same content.
|
||||||
|
|
||||||
int func(int &$val) {
|
int func(int &$val) {
|
||||||
|
|||||||
Reference in New Issue
Block a user