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