Revision 1 of 3, by Bart on 10-23-2022. The page as it is now.
$extendedSyntax
{$extendedSyntax on}turns on additional syntax. The FPC has this by default on. The short notation is
{$X+}/
{$X‑}.
Affected syntax
-
Functions can be called as if they were 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 operator can turn any
recordinto a managed data type.
-
Integer arithmetic expressions are allowed on pointers. The directive [[$pointerMath|
{$pointerMath}]] had to be on for that during the respective pointer type’s definition.
-
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.
Notes
-
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#Special behaviors|
incand
dec]]:
{$extendedSyntax off} var
p: pChar;
begin
p := nil;
inc(p, 42); { no problem }
end.
</syntaxhighlight>
Similarly, unusual comparison operations may be accessible with foreign routines.
- Built-in functions can never be called as if they were procedures
{$extendedSyntax on} begin
pi; { discardFunctionResultDemo.pas(4,4) Error: Illegal expression }
end.
</syntaxhighlight>
even though a custom [https://www.freepascal.org/docs-html/rtl/system/pi.html
pifunction] doing exactly the same would be acceptable.
-
Although with
{$extendedSyntax on}pointers become ordered, they do not become ordinal data types; the standard functions [[Ord|
ord]],
succand
predare still not applicable on pointers.
Comparative remarks
- Standard Pascal does not define any of those “extensions”.
See also
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.
