我错过了一些关于Ada和类型的基本想法。我只想做这样的事:
procedure Example( rec_len : in interfaces.c.short ) is
shortLen : Short_integer := 0;
recLen : integer := 0;
begin -- example
shortLen := rec_len; -- and
recLen := shortLen;
Text_IO.Put_Line( "rec length = "& Integer'IMAGE( recLen ));
end example;换句话说,从C语言short类型中获取整数值。
在i-c.ads中,short的定义是相同的--
type short is new Short_Integer;我找不到一个引用或例子来显示完成这个简单操作所需的合成糖。
在行:shortLen := rec_len中,GNAT编译器表示“Standard.Short_Integer类型的期望”,这当然是正确的。然而,我还没有找到一个合适的"to_Short()类型的调用“。我意识到这是一个基本的问题,我仍然认为它应该是我可以在某个地方(容易??)找到的东西。
发布于 2019-03-18 02:06:18
Ada (与C不同)不允许将一个数值类型的值赋值给另一个数值类型的变量,而不需要显式转换。
这应该是可行的:
shortLen := Short_Integer(rec_len);
recLen := Integer(shortLen);本声明:
type short is new Short_Integer;不会使short成为Short_Integer的别名(就像typedef在C中所做的那样)。它使short成为从Short_Integer派生出来的一种新的、独特的类型。
https://stackoverflow.com/questions/55213782
复制相似问题