wil*_*ill 1 c ada type-conversion
我缺少有关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;
Run Code Online (Sandbox Code Playgroud)
In other words jut get the integer value from the C language short type.
in the i-c.ads the definition for short is the same --
type short is new Short_Integer;
Run Code Online (Sandbox Code Playgroud)
i can't find a reference or example that shows the syntatic sugar needed to do that simple operation.
On the line: shortLen := rec_len, the GNAT compiler says "expected type Standard.Short_Integer", which is of course. However, I haven't found a suitable "to_Short() type call that works. I realise it is a basic question, I still think it ought to be something I can find in a document someplace(easily???). Thanks in advance for your know-how.
Ada(与C不同)不允许您在没有显式转换的情况下将一种数字类型的值分配给另一种数字类型的变量。
这应该工作:
shortLen := Short_Integer(rec_len);
recLen := Integer(shortLen);
Run Code Online (Sandbox Code Playgroud)
此声明:
type short is new Short_Integer;
Run Code Online (Sandbox Code Playgroud)
不会为它做short别名Short_Integer(就像typedef在C中一样)。它将short衍生出一个新的独特类型Short_Integer。