集合中是否允许负整数?
Are negative integers allowed in sets?
我知道集合在 FPC 中不能超过 255 个元素,但是,允许负整数吗?
我偶然发现了这个,但一直无法在网上找到与之相关的任何内容。
PROGRAM test;
TYPE rg = -10..0;
negatives = set of rg;
我遇到这个编译错误。
test.pas(3,25) Error: illegal type declaration of set elements
我怀疑这个错误来自负整数,因为如果我将范围定义为 0..5
,它编译正常。
来自 Delphi documentation,通常是 FP 镜像:
The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values of the set type are all the subsets of the base type, including the empty set. The base type can have no more than 256 possible values, and their ordinalities must fall between 0 and 255.
FreePascal docs说的是同样的事情(不太清楚,而且更难找到):
Each of the elements of SetType must be of type TargetType. TargetType can be any ordinal type with a range between 0 and 255.
我知道集合在 FPC 中不能超过 255 个元素,但是,允许负整数吗?
我偶然发现了这个,但一直无法在网上找到与之相关的任何内容。
PROGRAM test;
TYPE rg = -10..0;
negatives = set of rg;
我遇到这个编译错误。
test.pas(3,25) Error: illegal type declaration of set elements
我怀疑这个错误来自负整数,因为如果我将范围定义为 0..5
,它编译正常。
来自 Delphi documentation,通常是 FP 镜像:
The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values of the set type are all the subsets of the base type, including the empty set. The base type can have no more than 256 possible values, and their ordinalities must fall between 0 and 255.
FreePascal docs说的是同样的事情(不太清楚,而且更难找到):
Each of the elements of SetType must be of type TargetType. TargetType can be any ordinal type with a range between 0 and 255.