@/fi: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | 1 | @ | |
| 4 | - | ||
| 5 | - | ||
| 6 | 2 | ||
| 7 | 3 | Osoiteoperaattori `@` palauttaa [[Variable/fi|muuttujan]], [[Procedure/fi|aliohjelman]] tai [[Function/fi|funktion]] osoitteen. | |
| 8 | 4 | ||
| 9 | 5 | Normaalisti `@` palauttaa *tyypittömän* [[Pointer/fi|osoittimen]] arvon. Jos käsittellään osoittimia paljon ja halutaan vähentää virheitä jotka johtuvat viittauksista väärään tyyppiseen kohteeseen käytetään [[Compiler directive/fi|kääntäjän ohjetta]] [[sTypedaddress|{$typedaddress on}]]. | |
| 10 | 6 | ||
| 11 | 7 | Seuraavassa on esimerkki, mikä tuottaa tyypittömien osoittimien kanssa kelvollista ja toiminnallista koodia, mutta antaa virheellisen tuloksen: | |
| 12 | 8 | ||
| 13 | 9 | ``` pascal | |
| 14 | 10 | program untypedAddressDemo(input, output, stderr); | |
| 15 | 11 | ||
| 16 | 12 | procedure incrementIntByRef(const ref: PByte); | |
| 17 | 13 | begin | |
| 18 | 14 | inc(ref^); | |
| 19 | 15 | end; | |
| 20 | 16 | ||
| 21 | 17 | var | |
| 22 | 18 | foo: integer; | |
| 23 | 19 | begin | |
| 24 | 20 | foo := -1; | |
| 25 | 21 | incrementIntByRef(@foo); | |
| 26 | 22 | writeLn(foo); | |
| 27 | 23 | end. | |
| 28 | 24 | ``` | |
| 29 | 25 | ||
| 30 | 26 | Tarkoituksena oli, että `0` (nolla) tulostuu, mutta ohjelma tulostaa `-256`. Kun lisätään koodiin `{$typedaddress on}` niin käätäminen keskeytyy yhteensovittomaan tyyppivirheeseen. Tavallisesti halutaan viimeksi mainittu käyttäytyminen ([[Compile time/fi|käännösaikainen]] virhe) sen sijaan, että tuhlataan aikaa tuntikausia virheenkorjaukseen. | |
| 31 | 27 | ||
| 32 | 28 | ## Muita huomautuksia | |
| 33 | 29 | ||
| 34 | 30 | - [[ASCII/fi|ASCII]]:ssa merkin `@` (AT merkki): arvo on `64`. | |
| 35 | 31 | ||
| 36 | 32 | ## Lisää aiheesta | |
| 37 | 33 | ||
| 38 | 34 | - [The `@` operator](https://www.freepascal.org/docs-html/ref/refse83.html) | |
| 39 | 35 | - [Typed address operator (`@`)](https://www.freepascal.org/docs-html/prog/progsu75.html) | |
| 40 | 36 | - [`system.addr`](https://www.freepascal.org/docs-html/rtl/system/addr.html) | |
| 41 | 37 | ||
| 42 | 38 | --- | |
| 43 | 39 | *From the Free Pascal wiki, page "@/fi", as it stood on 2022-08-06 after a change by Kai Burghardt, 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).* |
