Sign in Join
Wiki copytemporary

@: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<div style="float:left; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
2-
31@
4-
5-</div>
62
73The address operator `@` returns the address of an [[Identifier|identifier]] that is associated with an address (usually a [[Variable|variable]] or [[Routine|routine]], but also a [[Label|label]]).
84
95Normally, the value `@` returns is an *untyped* [[Pointer|pointer]]. If you are handling pointers a lot, and want to mitigate issues with passing references of wrong type’s target, you have use the [[Compiler directive|directive]] [[$typedAddress|{$typedAddress on}]].
106
117Here is an example to demonstrate what produces with untyped pointers valid and functional code, but semantically outputs an erroneous result:
128
139``` pascal
1410program untypedAddressDemo(input, output, stderr);
1511
1612procedure incrementIntByRef(const ref: PByte);
1713begin
1814 inc(ref^);
1915end;
2016
2117var
2218 foo: integer;
2319begin
2420 foo := -1;
2521 incrementIntByRef(@foo);
2622 writeLn(foo);
2723end.
2824```
2925
3026It was intended that `0` (zero) gets printed, but the program prints `-256` instead. With `{$typedAddress on}` compilation fails with an incompatible type error. You usually want the latter behavior ([[compile-time error]]) instead of wasting time with hours of debugging.
3127
3228## other remarks
3329
3430- In [[ASCII]] the character `@` (AT sign): has the value `64`.
3531- [[PXSC]] defines the `loc` function as the address-operator.
3632
3733## read more
3834
3935- [The `@` operator](https://www.freepascal.org/docs-html/ref/refse87.html)
4036- [Typed address operator (`@`)](https://www.freepascal.org/docs-html/prog/progsu75.html)
4137- [[Addr|addr]]
4238
4339---
4440*From the Free Pascal wiki, page "@", as it stood on 2024-02-28 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history