$extendedSyntax: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | The [[global compiler directives|global compiler directive]] `{$extendedSyntax on}` turns on additional syntax. The [[FPC]] has this by default *on*. The short notation is `{$X+}`/`{$X‑}`. | |
| 2 | 2 | ||
| 3 | 3 | ## Affected syntax | |
| 4 | 4 | ||
| 5 | 5 | - [[Function|Functions]] can be called as if they were [[Procedure|procedures]]. The function result is discarded. This is potentially harmful if, for example, the function allocated new memory space and returned a pointer to it. Nonetheless, *managed data types* are insusceptible to leakage. Implementing a [[management operators|management operator]] can turn any `record` into a managed data type. | |
| 6 | 6 | - Integer *arithmetic* expressions are allowed on [[Pointer|pointers]]. The directive [[$pointerMath|{$pointerMath}]] had to be *on* for that *during* the respective pointer type’s definition. | |
| 7 | 7 | - Pointers become *ordered* and can be compared using [[Less than|<]],[[Greater than|>]], `<=` and `>=`. *Typed* pointers have to correspond to each other. The [[Equal|=]] and [[Not equal|<>]] comparisons work *regardless* of the `{$extendedSyntax}` state. | |
| 8 | 8 | ||
| 9 | 9 | ## Notes | |
| 10 | 10 | ||
| 11 | 11 | - If you have `{$extendedSyntax off}`, you can still do pointer arithmetic with routines from other units if they have been compiled with `{$extendedSyntax on}`, for example [[Inc and Dec|inc and dec]]: | |
| 12 | 12 | ||
| 13 | 13 | {\$extendedSyntax off} var | |
| 14 | 14 | ||
| 15 | 15 | ` p: pChar;` | |
| 16 | 16 | ||
| 17 | 17 | begin | |
| 18 | 18 | ||
| 19 | 19 | ` p := nil;`\ | |
| 20 | 20 | ` inc(p, 42); { no problem }` | |
| 21 | 21 | ||
| 22 | 22 | end. | |
| 23 | 23 | ||
| 24 | - | ||
| 25 | - | ||
| 26 | 24 | Similarly, unusual comparison operations may be accessible with foreign routines. | |
| 27 | 25 | ||
| 28 | 26 | - Built-in functions can never be called as if they were procedures | |
| 29 | 27 | ||
| 30 | 28 | {\$extendedSyntax on} begin | |
| 31 | 29 | ||
| 32 | 30 | ` pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }` | |
| 33 | 31 | ||
| 34 | 32 | end. | |
| 35 | - | ||
| 36 | - | ||
| 37 | 33 | ||
| 38 | 34 | even though a custom [`pi` `function`](https://www.freepascal.org/docs-html/rtl/system/pi.html) doing exactly the same would be acceptable. | |
| 39 | 35 | ||
| 40 | 36 | - Although with `{$extendedSyntax on}` pointers become ordered, they do *not* become *ordinal data types*; the standard functions [[Ord|ord]], `succ` and `pred` are still not applicable on pointers. | |
| 41 | 37 | ||
| 42 | 38 | ## Comparative remarks | |
| 43 | 39 | ||
| 44 | 40 | - [[Standard Pascal]] does not define any of those “extensions”. | |
| 45 | 41 | ||
| 46 | 42 | ## See also | |
| 47 | 43 | ||
| 48 | 44 | - [[Pascal for C users]] | |
| 49 | 45 | ||
| 50 | 46 | --- | |
| 51 | 47 | *From the Free Pascal wiki, page "$extendedSyntax", as it stood on 2022-10-23 after a change by Bart, 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).* |
