检查Ada中的空指针

the*_*yer 2 pointers ada

一般来说,Constraint_Error如果您尝试取消引用空指针(访问类型),Ada将引发一个.但是,例如,如果您pragma Suppress (all_checks)正在使用此行为,则会禁用此行为.

鉴于这种情况,如何检查访问类型是否指向0x0(null)?

考虑以下:

type My_Access_Type is access all My_Type'Class;

procedure myProcedure ( myAccess : in My_Access_Type ) is
begin

-- need to have check in here
end
Run Code Online (Sandbox Code Playgroud)

egi*_*lhh 7

if myAccess = null then
...
end if;
Run Code Online (Sandbox Code Playgroud)

虽然它不一定指向0x0.访问类型不是指针,并且可以以与普通地址不同的方式实现.