[英]In Ada is it possible to use 'others' on array initialisation for different values?
我想知道是否可以初始化这个数组:
Type Some is array (1..5) of Integer;
SomeArray : Some := ( 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 );
以某种不同的方式,像这样:
SomeArray : Some := ( others => n );
可能吗?
除了“某些”现在是Ada 2012中的保留字这一事实外,您可以完全按照您的描述初始化这种数组。 例如:
with Text_IO; use Text_IO;
procedure Agg_Init_Test is
type Some_Type is array (1.. 5) of Integer;
N : constant := 4;
Data : Some_Type := (others => N);
procedure Init_To (N : Integer) is
begin
Data := (others => N);
end Init_To;
procedure Init_Data (Data : out Some_Type; N : Integer) is
begin
Data := (others => N);
end Init_Data;
function Inc (Val : in out Integer) return Integer is
begin
Val := Val + 1;
return Val;
end Inc;
procedure Init_Seq(Data : out Some_Type; Start : Integer) is
N : Integer := Start;
begin
Data := (others => Inc(N));
end Init_Seq;
begin
Init_To(42);
Init_Data(Data, 2012);
Init_Seq(Data, 0);
for I of Data loop
Put_Line(Integer'Image(I));
end loop;
end Agg_Init_Test;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.