Basic Pascal Tutorial/Chapter 4/Forward Referencing: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Basic Pascal Tutorial/Chapter 4/Forward Referencing
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 4F - Forward Referencing (author: Tao Yue, state: unchanged) | |
| 2 | + | ||
| 3 | + | After all these confusing topics, here's something easy. | |
| 4 | + | ||
| 5 | + | Remember that procedures/functions can only see variables and other subprograms that have already been defined? Well, there is an exception. | |
| 6 | + | ||
| 7 | + | If you have two subprograms, each of which calls the other, you have a dilemma that no matter which you put first, the other still can't be called from the first. | |
| 8 | + | ||
| 9 | + | To resolve this chicken-and-the-egg problem, use *forward referencing*. | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 12 | + | procedure Later (parameter list); forward; | |
| 13 | + | ||
| 14 | + | procedure Sooner (parameter list); | |
| 15 | + | begin | |
| 16 | + | ... | |
| 17 | + | Later (parameter list); | |
| 18 | + | end; | |
| 19 | + | ... | |
| 20 | + | procedure Later; | |
| 21 | + | begin | |
| 22 | + | ... | |
| 23 | + | Sooner (parameter list); | |
| 24 | + | end; | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | The same goes for functions. Just stick a forward; at the end of the heading. | |
| 28 | + | ||
| 29 | + | --- | |
| 30 | + | *From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Forward Referencing", as it stood on 2022-08-20 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).* |
