Ada语言数组的访问类型(指针)
Ada语言中,存在着两种尺寸的访问类型,一种是32位,一种是64位。前者属于固定大小类型的
访问类型,后者属于不定长数组的访问类型,该类型是一个数据结构,包含数组首个元素的地址以及对数组范围结构的指针。
type LPSTR is access all String;
Name:LPSTR:=new String'("Ada Lovelace");
-- 范围结构,包含首尾序标
type scope is record
first,last:integer;
end record;
type ASTR is record
Element:access character;
index :access scope;
end record;
RangeName:scope:=(first=>1,last=>12);
AccessName:ASTR:=(Element=>Name(Name'first)'unrestricted_access,RangeName'unrestricted_access);
function As_LPSTR is new ada.unchecked_conversion(ASTR,LPSTR);
pName:LPSTR:=As_LPSTR(AccessName);
Ada.text_io.put_line(pName.all);-- 输出:Ada LoveLace