Sign in Join
Wiki copytemporary

$extendedSyntax: what changed

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

OldNewLine
1-The [[global compiler directives|global compiler directive]]
2-
3-``` pascal
4-{$extendedSyntax on}
5-```
6-
7-turns on additional syntax. The [[FPC]] has this by default *on*. The short notation is
8-
9-``` pascal
10-{$X+}
11-```
12-
13-/
14-
15-``` pascal
16-{$X‑}
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‑}`.
202
213## Affected syntax
224
23-- [[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
24- ``` pascal
25- record
26- ```
27-
28- into a managed data type.
29-- Integer *arithmetic* expressions are allowed on [[Pointer|pointers]]. The directive \[\[\$pointerMath\|
30- ``` pascal
31- {$pointerMath}
32- ```
33-
34- \]\] had to be *on* for that *during* the respective pointer type’s definition.
35-- Pointers become *ordered* and can be compared using \[\[Less than\|
36- ``` pascal
37- <
38- ```
39-
40- \]\],\[\[Greater than\|
41-
42- ``` pascal
43- >
44- ```
45-
46- \]\],
47-
48- ``` pascal
49- <=
50- ```
51-
52- and
53-
54- ``` pascal
55- >=
56- ```
57-
58- . *Typed* pointers have to correspond to each other. The \[\[Equal\|
59-
60- ``` pascal
61- =
62- ```
63-
64- \]\] and \[\[Not equal\|
65-
66- ``` pascal
67- <>
68- ```
69-
70- \]\] comparisons work *regardless* of the
71-
72- ``` pascal
73- {$extendedSyntax}
74- ```
75-
76- state.
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|&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.
778
789## Notes
7910
80-- If you have
81- ``` pascal
82- {$extendedSyntax off}
83- ```
84-
85- , you can still do pointer arithmetic with routines from other units if they have been compiled with
86-
87- ``` pascal
88- {$extendedSyntax on}
89- ```
90-
91- , for example \[\[Inc and Dec#Special behaviors\|
92-
93- ``` pascal
94- inc
95- ```
96-
97- and
98-
99- ``` pascal
100- dec
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]]:
10412
10513{\$extendedSyntax off} var
10614
10715`   p: pChar;`
10816
10917begin
11018
11119`   p := nil;`\
11220`   inc(p, 42); { no problem }`
11321
11422end.
11523
11624</syntaxhighlight>
11725
11826Similarly, unusual comparison operations may be accessible with foreign routines.
11927
12028- Built-in functions can never be called as if they were procedures
12129
12230{\$extendedSyntax on} begin
12331
12432`   pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }`
12533
12634end.
12735
12836</syntaxhighlight>
12937
130-even though a custom \[<https://www.freepascal.org/docs-html/rtl/system/pi.html>
131-
132-``` pascal
133-pi
134-```
135-
136-``` pascal
137-function
138-```
139-
140-\] doing exactly the same would be acceptable.
141-
142-- Although with
143- ``` pascal
144- {$extendedSyntax on}
145- ```
146-
147- pointers become ordered, they do *not* become *ordinal data types*; the standard functions \[\[Ord\|
148-
149- ``` pascal
150- ord
151- ```
152-
153- \]\],
154-
155- ``` pascal
156- succ
157- ```
158-
159- and
160-
161- ``` pascal
162- pred
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.
16439
165- are still not applicable on pointers.
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.
16641
16742## Comparative remarks
16843
16944- [[Standard Pascal]] does not define any of those “extensions”.
17045
17146## See also
17247
17348- [[Pascal for C users]]
17449
17550---
17651*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