Sign in Join
Wiki copytemporary

$extendedSyntax: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11The [[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‑}`.
22
33## Affected syntax
44
55- [[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.
66- 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.
77- Pointers become *ordered* and can be compared using [[Less than|&lt;]],[[Greater than|&gt;]], `<=` and `>=`. *Typed* pointers have to correspond to each other. The [[Equal|=]] and [[Not equal|&lt;&gt;]] comparisons work *regardless* of the `{$extendedSyntax}` state.
88
99## Notes
1010
1111- 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]]:
1212
1313{\$extendedSyntax off} var
1414
1515`   p: pChar;`
1616
1717begin
1818
1919`   p := nil;`\
2020`   inc(p, 42); { no problem }`
2121
2222end.
2323
24-</syntaxhighlight>
25-
2624Similarly, unusual comparison operations may be accessible with foreign routines.
2725
2826- Built-in functions can never be called as if they were procedures
2927
3028{\$extendedSyntax on} begin
3129
3230`   pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }`
3331
3432end.
35-
36-</syntaxhighlight>
3733
3834even though a custom [`pi` `function`](https://www.freepascal.org/docs-html/rtl/system/pi.html) doing exactly the same would be acceptable.
3935
4036- 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.
4137
4238## Comparative remarks
4339
4440- [[Standard Pascal]] does not define any of those “extensions”.
4541
4642## See also
4743
4844- [[Pascal for C users]]
4945
5046---
5147*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).*

Back to history