Sign in Join
Wiki copytemporary

Compiler Mode/zh CN

Deutsch · English · Español · Français · Suomi · 中文(中国)

FPC 旨在成为商业 Pascal 编译器的(部分)自由开源替代品。 为了实现这一目标,引入了一个编译器开关来确定“编译器兼容模式”。

每种模式都隐含地启用或禁用某些语法要求或其他语言结构。 其中一些可以通过所谓的“模式开关”单独启用或禁用,详见下文。

modes 模式

编译器兼容模式可以在源代码中通过全局编译器指令{$mode}指定,或者通过命令行或fpc.cfg(5)参数-M指定。

以下是识别的九种编译器兼容模式:

这是原始的 FPC 模式。从 FPC 3.x 开始,如果源代码或命令行没有明确指定编译器兼容模式,这将是“默认模式”。

此模式为 FPC 模式添加了额外功能,包括但不限于 类、接口 和 异常。

这是 Turbo Pascal 兼容模式。它试图与 Borland TP 7.0 兼容,例如通过禁用函数重载。

这是 Delphi 兼容模式。

与 {$mode Delphi} 类似,但默认 string 类型是 unicodeString。

Mac Pascal 兼容模式。

GNU Pascal 兼容模式。

符合 ISO 7185 标准的兼容模式。

这是扩展 Pascal 模式。它尽可能符合 ISO 10206 标准。

此外,特殊模式 default 会恢复任何指定的编译器兼容模式。

由于编译器兼容模式的指定隐含地施加了严格的变化,并且可能意味着包含其他模块,因此必须在其他任何内容之前指定这些指令。

模式开关 mode switch

自 FPC 2.3.1 起,全局编译器指令 {$modeSwitch} 允许在选择模式后选择性地启用或禁用某些特性。

模式开关必须出现在任何模式选择之后,否则模式开关将被覆盖。

pascal
// 尽管选择了 FPC 模式,但在将过程变量赋值时省略 @ 地址运算符
{$mode FPC}
{$modeSwitch classicProcVars+} // 在 FPC 模式下,为过程变量赋值时省略 @ 地址运算符

另请参阅


From the Free Pascal wiki, page "Compiler Mode/zh CN", as it stood on 2024-05-03 after a change by Hieroly, 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.

Revision 2, last changed by WikiArchive .

Edited on wiki.freepascal.org by 1 person, 2024

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
HierolyCreated page
Hieroly
Hieroly
Hieroly

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.