以前話題になっていたこの記事であるが、Adaの場合Segmentation Faultが起こる前に言語側で制約違反が起こるので、例外処理がきちんと出来ていれば即死を免れることが出来る。
procedure Pointer is
N :access Integer;
begin
begin
N.all := 5;
exception
when Constraint_Error =>
-- do something
end;
end Pointer;いや、そもそもAdaならnot null accessがあるので、このようなコードを書いてしまう状況になるかどうかも疑わしい。
procedure Pointer is
N : not null access Integer := new Integer'(5);
begin
-- do something
end Pointer;この場合、宣言部で初期化をしないとコンパイラがwarningを吐くので間違いに気がつくことが出来る。
もちろん、毎回not nullを書くのは面倒であるし、もしかしたら書き忘れてしまうかもしれない。そういう場合は型自体を定義してしまえばいい。
procedure Pointer is
type Integer_Access is not null access Integer;
N : Integer_Access := new Integer'(5);
begin
-- do something
end Pointer;
これで安心である。
http://yudai.arielworks.com/memo/2008/04/14/170807.trackback
末尾に「7 + 8」の計算結果を繋げて下さい。例えば計算結果が「17」の場合、「170807.trackback17」です。これは機械的なトラックバックスパムを防止するための措置です。