Difference between revisions of "^"
m |
(mention dereferencing) |
||
Line 4: | Line 4: | ||
In [[ASCII]] the character code decimal <syntaxhighlight lang="pascal" enclose="none">94</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" enclose="none">5E</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> (circumflex accent). | In [[ASCII]] the character code decimal <syntaxhighlight lang="pascal" enclose="none">94</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" enclose="none">5E</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> (circumflex accent). | ||
− | For any data type, a [[Pointer|pointer]] | + | For any data type, a [[Pointer|<syntaxhighlight lang="pascal" enclose="none">pointer</syntaxhighlight> type]] for that data can be declared using the operator <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> in front of the data type. |
+ | |||
+ | A <syntaxhighlight lang="pascal" enclose="none">pointer</syntaxhighlight> can be followed by appending a <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> to the identifier. | ||
+ | Instead of having the memory address in your hands, you will look at the memory content ''at'' that address. | ||
+ | If it is a typed <syntaxhighlight lang="pascal" enclose="none">pointer</syntaxhighlight> operations and syntax for that type are valid, e.g. [[Becomes|assignment]] in the following example. | ||
Line 16: | Line 20: | ||
type | type | ||
listItem = record | listItem = record | ||
− | + | payload: integer; | |
// next _points_ _to_ a list item | // next _points_ _to_ a list item | ||
next: ^listItem; | next: ^listItem; | ||
Line 32: | Line 36: | ||
end; | end; | ||
− | // _de-reference_ the pointer, follow it | + | // _de-reference_ the pointer, i.e. follow it |
− | start^. | + | start^.payload := 7; |
dispose(start); | dispose(start); | ||
end.</syntaxhighlight> | end.</syntaxhighlight> | ||
+ | |||
+ | == see also == | ||
+ | * [[sPointermath|<syntaxhighlight lang="pascal" enclose="none">{$pointerMath}</syntaxhighlight>]] | ||
+ | * [[sTypedaddress|<syntaxhighlight lang="pascal" enclose="none">{$typedAddress}</syntaxhighlight>]] in conjunction wtih the [[@|<syntaxhighlight lang="pascal" enclose="none">@</syntaxhighlight>-address-operator]] | ||
{{Symbols}} | {{Symbols}} | ||
[[Category:Code]] | [[Category:Code]] |
Revision as of 17:51, 3 April 2018
│
English (en) │
suomi (fi) │
русский (ru) │
In ASCII the character code decimal 94
(or hexadecimal 5E
) is defined to be ^
(circumflex accent).
For any data type, a pointer
type for that data can be declared using the operator ^
in front of the data type.
A pointer
can be followed by appending a ^
to the identifier.
Instead of having the memory address in your hands, you will look at the memory content at that address.
If it is a typed pointer
operations and syntax for that type are valid, e.g. assignment in the following example.
1program pointerDemo(input, output, stderr);
2
3type
4 listItem = record
5 payload: integer;
6 // next _points_ _to_ a list item
7 next: ^listItem;
8 end;
9
10var
11 start: ^listItem;
12
13begin
14 new(start);
15 if not assigned(start) then
16 begin
17 writeLn(stderr, 'obtaining memory for start failed');
18 halt(1);
19 end;
20
21 // _de-reference_ the pointer, i.e. follow it
22 start^.payload := 7;
23
24 dispose(start);
25end.
see also
{$pointerMath}
{$typedAddress}
in conjunction wtih the@
-address-operator
single characters |
|
character pairs |
|