Sign in Join
Wiki copytemporary

Compiler Mode/zh CN: what changed

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

Title: Compiler Mode/zh CN

OldNewLine
1+[[FPC]] 旨在成为商业 [[Pascal]] 编译器的(部分)自由开源替代品。 为了实现这一目标,引入了一个编译器开关来确定“编译器兼容模式”。
2+
3+每种模式都隐含地启用或禁用某些语法要求或其他语言结构。 其中一些可以通过所谓的“模式开关”单独启用或禁用,详见下文。
4+
5+## modes 模式
6+
7+编译器兼容模式可以在[[Source code|源代码]]中通过[[global compiler directives|全局编译器指令]]`{$mode}`指定,或者通过命令行或`fpc.cfg(5)`参数`-M`指定。
8+
9+以下是识别的九种编译器兼容模式:
10+
11+ * Free Pascal ([[Mode FPC|`{$mode FPC}`]], `-MFPC`)
12+
13+ 这是原始的 FPC 模式。从 FPC 3.x 开始,如果源代码或命令行没有明确指定编译器兼容模式,这将是“默认模式”。
14+
15+ * Object Pascal ([[Mode ObjFPC|`{$mode objFPC}`]], `-MobjFPC` 或 `-S2`)
16+
17+ 此模式为 `FPC` 模式添加了额外功能,包括但不限于 [[Class|类]]、[[Interface|接口]] 和 [[Exceptions|异常]]。
18+
19+ * [[Turbo Pascal]] ([[Mode TP|`{$mode TP}`]], `-MTP` 或 `-So`)
20+
21+ 这是 Turbo Pascal 兼容模式。它试图与 Borland TP 7.0 兼容,例如通过禁用函数重载。
22+
23+ * [[Delphi]] ([[Mode Delphi|`{$mode Delphi}`]], `-Mdelphi` 或 `-Sd`)
24+
25+ 这是 Delphi 兼容模式。
26+
27+ * Delphi with Unicode (`{$mode DelphiUnicode}`, `-MdelphiUnicode`) [自 FPC 3.0.0 起]
28+
29+ 与 `{$mode Delphi}` 类似,但默认 `string` 类型是 `unicodeString`。
30+
31+ * [[Mac Pascal]] ([[Mode MacPas|`{$mode MacPas}`]], `-MmacPas`) [since FPC 1.9.0]
32+
33+ Mac Pascal 兼容模式。
34+
35+ * [[GNU Pascal]] ([[Mode GPC|`{$mode GPC}`]], `-MGPC` 或 `-Sp`) [removed since FPC 2.2.0]
36+
37+ GNU Pascal 兼容模式。
38+
39+ * ISO 7185 [[Standard Pascal]] ([[Mode iso|`{$mode ISO}`]], `-MISO`) [[FPC New Features 2.6.0|[since FPC 2.6.0]]]
40+
41+ 符合 ISO 7185 标准的兼容模式。
42+
43+ * [[Extended Pascal]] ([[Mode extendedpascal|`{$mode extendedPascal}`]]) [since FPC 3.2]
44+
45+ 这是扩展 Pascal 模式。它尽可能符合 ISO 10206 标准。
46+
47+此外,特殊模式 `default` 会恢复任何指定的编译器兼容模式。
48+
49+由于编译器兼容模式的指定隐含地施加了严格的变化,并且可能意味着包含其他模块,因此必须在其他任何内容之前指定这些指令。
50+
51+## 模式开关 mode switch
52+
53+自 FPC 2.3.1 起,全局编译器指令 [[modeswitches|`{$modeSwitch}`]] 允许在选择模式后选择性地启用或禁用某些特性。
54+
55+模式开关必须出现在任何模式选择之后,否则模式开关将被覆盖。
56+```
57+// 尽管选择了 FPC 模式,但在将过程变量赋值时省略 @ 地址运算符
58+ {$mode FPC}
59+ {$modeSwitch classicProcVars+} // 在 FPC 模式下,为过程变量赋值时省略 @ 地址运算符
60+```
61+
62+## 另请参阅
63+
64+ * [_Free Pascal 用户手册_ 中的“编译器模式”部分](<https://www.freepascal.org/docs-html/user/userse33.html>)
65+
66+---
67+*From the Free Pascal wiki, page "Compiler Mode/zh CN", as the Internet Archive kept it on 2025-01-18. 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