@/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: @/fi
| Old | New | Line | |
|---|---|---|---|
| 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 | + | ||
| 3 | + | @ | |
| 4 | + | ||
| 5 | + | </div> | |
| 6 | + | ||
| 7 | + | Osoiteoperaattori `@` palauttaa [[Variable/fi|muuttujan]], [[Procedure/fi|aliohjelman]] tai [[Function/fi|funktion]] osoitteen. | |
| 8 | + | ||
| 9 | + | 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 | + | ||
| 11 | + | Seuraavassa on esimerkki, mikä tuottaa tyypittömien osoittimien kanssa kelvollista ja toiminnallista koodia, mutta antaa virheellisen tuloksen: | |
| 12 | + | ||
| 13 | + | ``` pascal | |
| 14 | + | program untypedAddressDemo(input, output, stderr); | |
| 15 | + | ||
| 16 | + | procedure incrementIntByRef(const ref: PByte); | |
| 17 | + | begin | |
| 18 | + | inc(ref^); | |
| 19 | + | end; | |
| 20 | + | ||
| 21 | + | var | |
| 22 | + | foo: integer; | |
| 23 | + | begin | |
| 24 | + | foo := -1; | |
| 25 | + | incrementIntByRef(@foo); | |
| 26 | + | writeLn(foo); | |
| 27 | + | end. | |
| 28 | + | ``` | |
| 29 | + | ||
| 30 | + | 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 | + | ||
| 32 | + | ## Muita huomautuksia | |
| 33 | + | ||
| 34 | + | - [[ASCII/fi|ASCII]]:ssa merkin `@` (AT merkki): arvo on `64`. | |
| 35 | + | ||
| 36 | + | ## Lisää aiheesta | |
| 37 | + | ||
| 38 | + | - [The `@` operator](https://www.freepascal.org/docs-html/ref/refse83.html) | |
| 39 | + | - [Typed address operator (`@`)](https://www.freepascal.org/docs-html/prog/progsu75.html) | |
| 40 | + | - [`system.addr`](https://www.freepascal.org/docs-html/rtl/system/addr.html) | |
| 41 | + | ||
| 42 | + | --- | |
| 43 | + | *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).* |
