私はAdaを使いました。Ada outパラメータ
私はこのquestionを見ましたが、私のは少し異なります。
type A is record
x : integer;
y : integer;
end record;
procedure P1 is
temp : A;
begin
temp.x := 100;
P2(temp);
if temp.x = 100 then
Ada.Text_IO.Put_Line("true");
else
Ada.Text_IO.Put_Line("false");
end if;
end One;
procedure P2 (arg1 : out A) is
begin
arg1.y := 200;
end P2;
私の質問はP2に「アウト」パラメータである:P2が明示的にしなかった場合は、複合タイプの他の部分は不定となりますそれらを設定します。言い換えれば、P1が呼び出された場合、出力は間違いなく真か偽でしょうか?それともあいまいですか?
このlinkは「デフォルトの初期化」について述べていますが、上記の例では明示的に(意図的に)設定していません。
Safety is preserved by ensuring that a subcomponent does not become
"deinitialized" by being passed as an out parameter. If any subcomponent
of a type passed by copy has default initialization, then the whole
object is copied in at the start of the call so that the value of such a
subcomponent is not lost as a result of a subprogram call during which
no assignment is made to the subcomponent. But in practice records are
usually passed by reference anyway.
コンパイラ固有の動作かどうかはわかりませんが、コピーを渡すことができたコンパイラは同じように動作しますか?私はそれを危険にさらさないようにしよう! –
@trashgodありがとうございました。コンパイラに依存している場合は、 "in out"を使用して確実に動作することを確認します(渡されたレコードがデフォルトの初期化を持っているかどうかわからない場合): 'プロシージャP2(arg1:out A) ' ' begin' 'arg1.y:= 200;' 'end P2;' –
@TNguyen:私は上記で詳述しました。 – trashgod