Sign in Join
Wiki copytemporary

Compiler Mode: what changed

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

Title: Compiler Mode

OldNewLine
1+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.
2+
3+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.
4+
5+## modes
6+
7+A compiler compatibility mode can be specified in [[Source code|source code]] via the [[global compiler directives|global compiler directive]] `{$mode}` or via the command line or `fpc.cfg(5)` parameter `-M`.
8+
9+The following nine compiler compatibility modes are recognized:
10+
11+Free Pascal ([[Mode FPC|{$mode FPC}]], `-MFPC`)
12+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.
13+
14+Object Pascal ([[Mode ObjFPC|{$mode objFPC}]], `-MobjFPC` or `-S2`)
15+This mode adds extra functionality to the `FPC` mode, including but not limited to [[Class|classes]], [[Interface|interfaces]] and [[Exceptions|exceptions]].
16+
17+[[Turbo Pascal]] ([[Mode TP|{$mode TP}]], `-MTP` or `-So`)
18+This is the Turbo Pascal compatibility mode. It tries to be compatible to Borland TP 7.0, e. g. by disable function overloading.
19+
20+[[Delphi]] ([[Mode Delphi|{$mode Delphi}]], `-Mdelphi` or `-Sd`)
21+This is the Delphi compatibility mode.
22+
23+Delphi with Unicode (`{$mode DelphiUnicode}`, `-MdelphiUnicode`) \[[[FPC New Features 3.0|since FPC 3.0.0]]\]
24+Like `{$mode Delphi}` but with `unicodeString` as default `string` type.
25+
26+[[Mac Pascal]] ([[Mode MacPas|{$mode MacPas}]], `-MmacPas`) \[since FPC 1.9.0\]
27+The Mac Pascal compatibility mode.
28+
29+[[GNU Pascal]] ([[Mode GPC|{$mode GPC}]], `-MGPC` or `-Sp`) \[removed since FPC 2.2.0\]
30+The GNU Pascal compatibility mode.
31+
32+ISO 7185 [[Standard Pascal]] ([[Mode iso|{$mode ISO}]], `-MISO`) \[[[FPC New Features 2.6.0|since FPC 2.6.0]]\]
33+The ISO 7185 compliant compatibility mode.
34+
35+[[Extended Pascal]] ([[Mode extendedpascal|{$mode extendedPascal}]]) \[since FPC 3.2\]
36+This is the extended Pascal mode. It tries to be as ISO 10206 compliant as possible.
37+
38+Furthermore the special mode `default` reverts any specifications of a compiler compatibility mode.
39+
40+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.
41+
42+## mode switch
43+
44+Since FPC 2.3.1 the global compiler directive [[modeswitches|{$modeSwitch}]] allows a selective selection of *some* features, despite the chosen mode.
45+
46+A mode switch has to appear after any mode selections, otherwise the mode switches will be overwritten.
47+
48+``` pascal
49+// omit @-address-operator while assigning to procedural variables, despite FPC mode
50+{$mode FPC}
51+{$modeSwitch classicProcVars+}
52+```
53+
54+## see also
55+
56+- [§ “compiler modes” in the *Free Pascal User’s manual*](https://www.freepascal.org/docs-html/user/userse33.html)
57+
58+---
59+*From the Free Pascal wiki, page "Compiler Mode", as it stood on 2019-10-21 after a change by Kai Burghardt, 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