Sign in Join
Wiki copytemporary

$extendedSyntax: what changed

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

Title: $extendedSyntax

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+.
20+
21+## Affected syntax
22+
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.
77+
78+## Notes
79+
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+ \]\]:
104+
105+{\$extendedSyntax off} var
106+
107+`   p: pChar;`
108+
109+begin
110+
111+`   p := nil;`\
112+`   inc(p, 42); { no problem }`
113+
114+end.
115+
116+</syntaxhighlight>
117+
118+Similarly, unusual comparison operations may be accessible with foreign routines.
119+
120+- Built-in functions can never be called as if they were procedures
121+
122+{\$extendedSyntax on} begin
123+
124+`   pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }`
125+
126+end.
127+
128+</syntaxhighlight>
129+
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+ ```
164+
165+ are still not applicable on pointers.
166+
167+## Comparative remarks
168+
169+- [[Standard Pascal]] does not define any of those “extensions”.
170+
171+## See also
172+
173+- [[Pascal for C users]]
174+
175+---
176+*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