Ada 不同数组长度的未选中转换

Ada 不同数组长度的未选中转换,ada,Ada,我在以下情况下遇到约束错误: 从过程中获取受约束的缓冲区: Get_MyBuffer(data => Buffer); -- This is ok 缓冲区的类型为无符号字节。要将其转换为字节 function To_Byte is new Unchecked_Conversion (Source => Unsigned_Byte, Target => Byte); MyFunction

我在以下情况下遇到约束错误:

从过程中获取受约束的缓冲区:

Get_MyBuffer(data => Buffer); -- This is ok
缓冲区的类型为无符号字节。要将其转换为字节

function To_Byte is new Unchecked_Conversion (Source => Unsigned_Byte,
                                              Target => Byte);
MyFunction2Pass(To_Byte(Buffer)); -- Having warning 'uncheked conversion to unconstrained array subtype is not portable.
在MyFunction2Pass中打印

function MyFunction2Pass(Data : Byte) is
begin
    New_Line(integer'image(integer(Data(1)))); -- **Shoot Constrain Error**
end

你的那一行做得太多了。这并没有什么错,但当您遇到此异常时,它暂时不起作用。您可以考虑将每个例程调用拆分为自己的行,这样就可以跟踪哪个调用正在发出约束错误。

    Bit     : constant boolean := Data(1);  -- I'm guessing this is the right type
    Bit_Int : constant integer := integer(Bit);
    Bit_Img : constant string  := integer'image(Bit_Int);
begin
    New_Line (Bit_Img);
end

现在哪一行给出了约束错误?(当然,在清除了所有编译器错误之后)。

你的一行代码做得太多了。这并没有什么错,但当您遇到此异常时,它暂时不起作用。您可以考虑将每个例程调用拆分为自己的行,这样就可以跟踪哪个调用正在发出约束错误。

    Bit     : constant boolean := Data(1);  -- I'm guessing this is the right type
    Bit_Int : constant integer := integer(Bit);
    Bit_Img : constant string  := integer'image(Bit_Int);
begin
    New_Line (Bit_Img);
end

现在哪一行给出了约束错误?(当然,在清除所有编译器错误之后)。

字节和无符号字节的定义是什么?警告意味着其中一个是无约束数组。字节和无符号字节的定义是什么?警告意味着其中一个是无约束数组。