Jestem nowy dla Ady.Ada out parameter
Widziałem ten question, ale mój jest trochę inna:
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;
Moje pytanie jest z parametrem „out” P2: będą inne części typu kompozytowego być niezdefiniowana jeśli nie jawnie P2 ustaw je. Innymi słowy, jeśli wywoływane jest P1, czy wynik byłby zdecydowanie prawdziwy czy fałszywy? A może niejednoznaczne?
Ta mówi o "domyślnej inicjalizacji", ale mój powyższy przykład nie ma tego wyraźnie (celowo).
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.
Nie jestem pewien, czy jest to zachowanie specyficzne dla kompilatora? Czy kompilator, który mógłby przejść przez kopiowanie, zachowuje się tak samo?Staram się nie ryzykować! –
Dziękuję @trashgod. Jeśli jest to zależne od kompilatora, to używa "out" jedynego pewny sposób, aby upewnić się, że działa (jeśli nie jesteś pewien, że przekazany rekord ma domyślną inicjalizację): 'procedura P2 (arg1: na wyjściu A) jest ' ' begin' 'arg1.y: = 200;' 'end P2;' –
@TNguyen: Opracowałem powyżej. – trashgod