Pointers and references: Difference between revisions

PascalABC.NET
m (→‎{{header|Wren}}: Changed to Wren S/H)
(PascalABC.NET)
 
(One intermediate revision by one other user not shown)
Line 675:
→ 666
</syntaxhighlight>
 
=={{header|Ecstasy}}==
In Ecstasy, all values are references to objects. These references are like pointers in C, but address information is not accessible, and no arithmetic operations can be performed on them. Additionally, each reference is itself an object, providing reflective information about the reference.
 
Objects are always accessed and manipulated through references, using the <code>.</code> ("dot") operator.
 
Ecstasy uses call-by-value. When passing arguments, all arguments are references, passed by value.
 
<syntaxhighlight lang="ecstasy">
module test {
@Inject Console console;
 
public class Point(Int x, Int y) {
@Override String toString() = $"({x},{y})";
}
 
void run() {
Point p = new Point(0, 0);
p.x = 7;
p.y = p.x;
console.print($"{p=}");
 
// obtain the reference object itself
Ref<Point> r = &p;
console.print($"{r.actualType=}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec test
p=(7,7)
r.actualType=Point
</pre>
 
=={{header|Forth}}==
Line 1,640 ⟶ 1,675:
foo(bar);
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
type MyClass = class
public
x: integer := 555;
end;
 
begin
var pi: ^integer;
New(pi);
pi^ := 1023;
var pb: ^byte;
//pb := pi; // compiler error
var p: pointer;
p := pi;
pb := p;
Print(pb^); // byte representation of integer
loop 3 do
begin
pb := pointer(integer(pb)+1); // analog of pb++
Print(pb^);
end;
Println;
var obj := new MyClass; // obj is a reference to object
// All regferences in .NET are under control of garbage collection
Println(obj);
var obj1 := obj; // another reference to the same object
obj1.x := 666;
Println(obj);
obj := nil; // zero reference
end.
</syntaxhighlight>
{{out}}
<pre>
255 3 0 0
(555)
(666)
</pre>
 
=={{header|Perl}}==
222

edits