kli*_*ing 6 delphi syntax compilation delphi-2007
我一直在为Delphi编程五六年,我认为自己相当擅长,但我最近偶然发现了一个我无法解释的行为.我正在编写一个简单的链表,我们称之为TIntegerList.下面的示例代码正确编译:
type
PIntegerValue = ^TIntegerValue;
TIntegerValue = record
Value: Integer;
Next: PIntegerValue;
Prev: PIntegerValue;
end;
Run Code Online (Sandbox Code Playgroud)
但是,下面的代码没有(说TIntegerValue未声明):
type
PIntegerValue = ^TIntegerValue;
type
TIntegerValue = record
Value: Integer;
Next: PIntegerValue;
Prev: PIntegerValue;
end;
Run Code Online (Sandbox Code Playgroud)
Delphi中"type"关键字究竟是如何处理的?与在每个类型中使用一个"类型"相比,在一个"type"关键字下声明多个类型的语法含义是什么?好吧,这令人困惑,但我希望代码示例有助于解释我的意思.我在Delphi 2007工作.
逻辑上,type当代码已经是现有类型声明部分的一部分时,不需要使用关键字.所以,
type
TRec1 = record
end;
TRec2 = record
end;
Run Code Online (Sandbox Code Playgroud)
产生无法区分的类型
type
TRec1 = record
end;
type
TRec2 = record
end;
Run Code Online (Sandbox Code Playgroud)
但是,正如您所发现的,编译器有一个限制,要求在引入前向声明的部分结束之前完全解析所有前向声明.
它没有特别的原因必须这样.编译器完全可以放宽该限制.人们只能假设很可能源于很久以前的编译器实现细节已经渗透到语言规范中.
| 归档时间: |
|
| 查看次数: |
317 次 |
| 最近记录: |