@: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | @ | |
| 2 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 3 | + | The 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]]). | |
| 6 | 4 | ||
| 7 | - | ||
| 5 | + | Normally, what 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 to use the [[Compiler directive|directive]] [`{$typedAddress on}`](</index.php?title=$typedAddress&action=edit&redlink=1> "$typedAddress \(page does not exist\)"). | |
| 8 | 6 | ||
| 9 | - | ||
| 7 | + | Here is an example to demonstrate what produces with untyped pointers valid and functional code, but semantically outputs an erroneous result: | |
| 8 | + | ``` | |
| 10 | 9 | program untypedAddressDemo(input, output, stderr); | |
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 10 | + | ||
| 11 | + | procedure incrementIntByRef(const ref: PByte); | |
| 12 | + | begin | |
| 13 | + | inc(ref^); | |
| 14 | + | end; | |
| 15 | + | ||
| 16 | + | var | |
| 17 | + | foo: integer; | |
| 18 | + | begin | |
| 19 | + | foo := -1; | |
| 20 | + | incrementIntByRef(@foo); | |
| 21 | + | writeLn(foo); | |
| 22 | + | end. | |
| 24 | 23 | ``` | |
| 25 | 24 | ||
| 26 | - | ||
| 25 | + | It 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. | |
| 27 | 26 | ||
| 28 | 27 | ## other remarks | |
| 29 | 28 | ||
| 30 | - | ||
| 31 | - | ||
| 29 | + | * In [[ASCII]] the character `@` (AT sign): has the value `64`. | |
| 30 | + | * [[PXSC]] defines the `loc` function as the address-operator. | |
| 32 | 31 | ||
| 33 | 32 | ## read more | |
| 34 | 33 | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 34 | + | * [The `@` operator](<https://www.freepascal.org/docs-html/ref/refse87.html>) | |
| 35 | + | * [Typed address operator (`@`)](<https://www.freepascal.org/docs-html/prog/progsu75.html>) | |
| 36 | + | * [[Addr|`addr`]] | |
| 38 | 37 | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + | navigation bar: topic: Pascal symbols single characters | [[Plus|`+` (plus)]] • [[Minus|`-` (minus)]] • [[*|`*` (asterisk)]] • [[Slash|`/` (slash)]] | |
| 41 | + | [[Equal|`=` (equal)]] • [[Greater than|`>` (greater than)]] • [[Less than|`<` (less than)]] | |
| 42 | + | [[period|`.` (period)]] • [[Colon|`:` (colon)]] • [[;|`;` (semi colon)]] | |
| 43 | + | [[^|`^` (hat)]] • `@` (at) | |
| 44 | + | [[Dollar sign|`$` (dollar sign)]] • [[&|`&` (ampersand)]] • [`#` (hash)](</index.php?title=Hash&action=edit&redlink=1> "Hash \(page does not exist\)") | |
| 45 | + | [['|`'` (single quote)]] | |
| 46 | + | ---|--- | |
| 47 | + | character pairs | [[Not equal|`<>` (not equal)]] • [[Less than or equal|`<=` (less than or equal)]] • [[Becomes|`:=` (becomes)]] • [[Greater than or equal|`>=` (greater than or equal)]] • [[symmetric difference|`><` (symmetric difference)]] • [[Slash|`//` (double slash)]] | |
| 48 | + | ||
| 49 | + | ||
| 50 | + | **** | |
| 51 | + | ||
| 39 | 52 | --- | |
| 40 | - | ||
| 53 | + | *From the Free Pascal wiki, page "@", as the Internet Archive kept it on 2025-03-17, last changed on 2024-07-18. 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).* |
