Compiler Mode

From Free Pascal wiki
Revision as of 15:12, 20 October 2019 by Kai Burghardt (talk | contribs) (refactor)
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr)

The FPC intends to be (in part) a free and open source alternative to commercial Pascal compilers. In order to achieve this a compiler switch determining the compiler compatibility mode has been introduced.

Every mode implicitly enables or disables certain syntax requirements or other language constructs. Some of these can be enabled or disabled on an individual basis by using so called mode switches, see below.

modes

A compiler compatibility mode can be specified in source code via the global compiler directive {$mode} or via the command line or fpc.cfg(5) parameter -M.

The following eight compiler compatibility modes are recognized:

Free Pascal ({$mode FPC}, -MFPC)
This is the original FPC mode. As of FPC 3.x this is the default mode if neither the source code or the command line specifies a compiler compatibility mode explicitly.
Object Pascal ({$mode objFPC}, -MobjFPC or -S2)
This mode adds extra functionality to the FPC mode, including but not limited to classes, interfaces and exceptions.
Turbo Pascal ({$mode TP}, -MTP or -So)
This is the Turbo Pascal compatibility mode. It tries to be compatible to Borland TP 7.0, e. g. by disable function overloading.
Delphi ({$mode Delphi}, -Mdelphi or -Sd)
This is the Delphi compatibility mode.
Mac Pascal ({$mode MacPas}, -MmacPas) [since FPC 1.9.0]
The Mac Pascal compatibility mode.
GNU Pascal ({$mode GPC}, -MGPC or -Sp) [suspended since FPC 2.4.0]
The GNU Pascal compatibility mode.
ISO 7185 Standard Pascal ({$mode ISO}, -MISO) [since FPC 2.6.0]
The ISO 7185 compliant compatibility mode.
Extended Pascal ({$mode extendedPascal}) [trunk only]
This will be the extended Pascal mode in a future release.

Furthermore the special mode default reverts any specifications of a compiler compatibility mode.

Since the specifications of compiler compatibility mode implicitly imposes rigorous changes and possibly implies inclusion of other modules, it is imperative to specify the directives prior any other.

mode switch

Since FPC 2.3.1 the global compiler directive {$modeSwitch} allows a selective selection of some features, despite the chosen mode.

A mode switch has to appear after any mode selections, otherwise the mode switches will be overwritten.

// allow exceptions, despite the normal FPC mode:
{$mode FPC}
{$modeSwitch exceptions+}

see also