Pascal 中区分大小写(以 Integer 为例)

Case sensitivity in Pascal (using Integer as example)

我的理解是,从Delphi 2009年开始,编译器只接受数据类型Integer。但是,有很多文章,例如 example 1 and example 2 showing mixed (!) usage of integer and Integer. AFAIK, Embarcadero websites exclusively uses Integer (good!) but the Wikipedia article on Pascal 专门使用 integer.

不幸的是,我无法使用其他 Pascal 编译器,但是 Delphi 7 接受 integerInteger:

int1: Integer;
int2: intEGER;          // Allowed in Delphi 7
struct1: MyRecord;
struct2: mYrEcOrD;      // Also allowed => source of bugs!

有人能告诉我 Pascal 是否正式区分大小写,以及这是否随着最新的 Delphi 编译器而改变。

与您的陈述相反,Pascal 不区分大小写。所以 Integerinteger 是相同的标识符。

documentation 声明如下:

Since the Delphi Language is case-insensitive, an identifier like CalculateValue could be written in any of these ways:

CalculateValue
calculateValue
calculatevalue
CALCULATEVALUE

您 link 在问题中看到的维基百科文章说:

Letter case is ignored in Pascal source.

一些作者更喜欢特定大写的事实绝不意味着编译器将不同的大写视为不同的标识符。它不是。

当然,大多数有经验的 Pascal 开发人员都会使用一致的大小写。代码在一致且大写时更易于阅读,例如在使用 Pascal 大小写命名约定时,将含义传达给 reader。

对我来说,这是将语言设计为区分大小写的动机。作为一般规则,如果开发人员关心某事,那么编译器也关心它通常是有帮助的。这样编译器可以检查开发人员没有犯错误。但是 Pascal 的大小写不敏感很久以前就确定了,并且出于兼容性的原因永远不会改变。

你的理解有误。 Delphi 的所有版本都接受任何数据类型和任何其他标识符的任何大写,外部互操作性除外,例如从 DLL 导入符号。