Compiler Mode

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 中文(中国大陆) (zh_CN)

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 nine 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.
Delphi with Unicode ({$mode DelphiUnicode}, -MdelphiUnicode) [since FPC 3.0.0]
Like {$mode Delphi} but with unicodeString as default string type.
Mac Pascal ({$mode MacPas}, -MmacPas) [since FPC 1.9.0]
The Mac Pascal compatibility mode.
GNU Pascal ({$mode GPC}, -MGPC or -Sp) [removed since FPC 2.2.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}) [since FPC 3.2]
This is the extended Pascal mode. It tries to be as ISO 10206 compliant as possible.

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.

// omit @-address-operator while assigning to procedural variables, despite FPC mode
{$mode FPC}
{$modeSwitch classicProcVars+}

see also