我很困惑如何'Size以及'Component_Size从文件中读取输入的工作时,并尝试使用Unchecked_Conversion。我知道要成功使用Unchecked_ConversionSource和Target都必须相同size。我正在从类似文件的输入中读取内容,000100000101001并希望使用未经检查的转换将其放入Bits数组中。但是,由于它们大小不一样或太小,因此转换似乎总是失败。
with Ada.Unchecked_Conversion;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure main is
type Bit is mod 2 with size => 1;
type Bit_Array is array(Positive range <>) of Bit with pack;
subtype Bit15 is Bit_Array(1 .. 15); //subtypes because can't use conversion on unconstrainted type
subtype Bit11 is Bit_Array(1 .. 11);
function StringA_to_Bit15 is
new Ada.Unchecked_Conversion(source => String, target => Bit15);
begin
while not end_of_file loop …Run Code Online (Sandbox Code Playgroud)