아래의 예에서 궁금한 점은 line 17
이 작동하지 않는 이유는 무엇입니까? line 18
? System.Address
을 Integer
(line 17
참조)로 직접 변환 할 수 있습니까?Ada의 System.Address에서 Integer로 변환
main.adb
with Ada.Text_IO;
with Ada.Unchecked_Conversion;
with System.Storage_Elements;
procedure Main is
package SSE renames System.Storage_Elements;
type Integer_Access is access Integer;
I1_Access : Integer_Access := new Integer'(42);
I1_Address : System.Address := I1_Access.all'Address;
function Convert1 is new Ada.Unchecked_Conversion (System.Address, Integer);
function Convert2 is new Ada.Unchecked_Conversion (System.Address, Integer_Access);
begin
Ada.Text_IO.Put_Line (SSE.To_Integer (I1_Access'Address)'Img);
Ada.Text_IO.Put_Line (SSE.To_Integer (I1_Access.all'Address)'Img);
Ada.Text_IO.Put_Line (I1_Access.all'Img);
Ada.Text_IO.Put_Line (Convert1 (I1_Address)'Img); -- why does this NOT work?
Ada.Text_IO.Put_Line (Convert2 (I1_Address).all'Img); -- why does this work?
end Main;
결과
140734773254664
140243203260416
42
-363855872
42
감사! 나는'Convert3 is new System.Address_To_Access_Conversions (Integer);와'Ada.Text_IO.Put_Line (Convert3.To_Pointer (I1_Address) .all'Img); '가 작동하는 패키지를 시도했다. 이제 Convert1이 작동하지 않는 이유도 있습니다. – user1091344