$extendedSyntax: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 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‑}`. | |
| 20 | 2 | ||
| 21 | 3 | ## Affected syntax | |
| 22 | 4 | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - | ||
| 76 | - | ||
| 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 | + | - 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 | + | - 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. | |
| 77 | 8 | ||
| 78 | 9 | ## Notes | |
| 79 | 10 | ||
| 80 | - | ||
| 81 | - | ||
| 82 | - | ||
| 83 | - | ||
| 84 | - | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 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]]: | |
| 104 | 12 | ||
| 105 | 13 | {\$extendedSyntax off} var | |
| 106 | 14 | ||
| 107 | 15 | ` p: pChar;` | |
| 108 | 16 | ||
| 109 | 17 | begin | |
| 110 | 18 | ||
| 111 | 19 | ` p := nil;`\ | |
| 112 | 20 | ` inc(p, 42); { no problem }` | |
| 113 | 21 | ||
| 114 | 22 | end. | |
| 115 | 23 | ||
| 116 | 24 | </syntaxhighlight> | |
| 117 | 25 | ||
| 118 | 26 | Similarly, unusual comparison operations may be accessible with foreign routines. | |
| 119 | 27 | ||
| 120 | 28 | - Built-in functions can never be called as if they were procedures | |
| 121 | 29 | ||
| 122 | 30 | {\$extendedSyntax on} begin | |
| 123 | 31 | ||
| 124 | 32 | ` pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }` | |
| 125 | 33 | ||
| 126 | 34 | end. | |
| 127 | 35 | ||
| 128 | 36 | </syntaxhighlight> | |
| 129 | 37 | ||
| 130 | - | ||
| 131 | - | ||
| 132 | - | ||
| 133 | - | ||
| 134 | - | ||
| 135 | - | ||
| 136 | - | ||
| 137 | - | ||
| 138 | - | ||
| 139 | - | ||
| 140 | - | ||
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | - | ||
| 154 | - | ||
| 155 | - | ||
| 156 | - | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - | ||
| 160 | - | ||
| 161 | - | ||
| 162 | - | ||
| 163 | - | ||
| 38 | + | even though a custom [`pi` `function`](https://www.freepascal.org/docs-html/rtl/system/pi.html) doing exactly the same would be acceptable. | |
| 164 | 39 | ||
| 165 | - | ||
| 40 | + | - 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. | |
| 166 | 41 | ||
| 167 | 42 | ## Comparative remarks | |
| 168 | 43 | ||
| 169 | 44 | - [[Standard Pascal]] does not define any of those “extensions”. | |
| 170 | 45 | ||
| 171 | 46 | ## See also | |
| 172 | 47 | ||
| 173 | 48 | - [[Pascal for C users]] | |
| 174 | 49 | ||
| 175 | 50 | --- | |
| 176 | 51 | *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).* |
