From: Vincent Marciante <marciant@li.net>
Subject: Assigning to dereferenced null access variable
Date: 2000/11/05
Date: 2000-11-05T00:00:00+00:00 [thread overview]
Message-ID: <3A05A609.4CE6@li.net> (raw)
In the following code, I expected a constraint_error to occur
after the line containing "???" but it did not occur. Is that
correct behavior?
Also, after that line, I expected the code in the two blocks
to behave the same but that was not the case. The following is the output that I get from OS/2 GNAT 3.12
abcd_Sequence.The_Characters.all = "abcd"
Null_Characters(1..0) = Null_Characters
Null_Sequence.The_Characters = null.
Null_Sequence.The_Characters(1..0) = Null_Characters
Null_Sequence.The_Characters(1..0) := Null_Characters(1..0) succeeded ?
Null_Sequence.The_Characters(1..0) := Null_Characters caused Constraint_Error ?
with Ada.Text_IO; Use Ada.Text_IO;
procedure Null_Sequence_Assignment is
type Characters is array (Positive range <>) of Character;
type Reference is access Characters;
type Character_Sequence is
record
The_Length : Natural := 0;
The_Characters : Reference;
end record;
Null_Characters : Characters(1..0);
abcd_Characters : Characters := "abcd";
Null_Sequence : Character_Sequence;
abcd_Sequence : Character_Sequence := (4, new Characters'(1=>'a',2=>'b',3=>'c',4=>'d'));
begin
abcd_Characters(1..0) := Null_Characters(1..0);
abcd_Characters(1..0) := Null_Characters;
Null_Characters := abcd_Characters(1..0);
abcd_Sequence.The_Characters(1..0) :=
Null_Characters;
abcd_Sequence.The_Characters(1..Null_Sequence.The_Length) :=
Null_Sequence.The_Characters(1..Null_Sequence.The_Length);
abcd_Sequence.The_Characters(1..0) :=
Null_Sequence.The_Characters(1..0);
abcd_Sequence.The_Characters(1..0) :=
Null_Characters;
put_line("abcd_Sequence.The_Characters.all = """
& String(abcd_Sequence.The_Characters.all) & '"');
--- ???
Null_Sequence.The_Characters(1..0) :=
-- Why no Constraint_Error here do to
-- dereferencing of null access value?
-- Is it due to allowed optimization?
abcd_Sequence.The_Characters(1..0);
if Null_Characters(1..0) = Null_Characters then
Put_Line("Null_Characters(1..0) = Null_Characters");
else
Put_Line("Null_Characters(1..0) /= Null_Characters");
end if;
if Null_Sequence.The_Characters = null then
Put_Line("Null_Sequence.The_Characters = null.");
else
Put_Line("Null_Sequence.The_Characters /= null.");
end if;
if Null_Sequence.The_Characters(1..0) = Null_Characters then
Put_Line("Null_Sequence.The_Characters(1..0) = Null_Characters");
else
Put_Line("Null_Sequence.The_Characters(1..0) /= Null_Characters");
end if;
begin
Null_Sequence.The_Characters(1..0) :=
Null_Characters(1..0);
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters(1..0) succeeded ?");
-- I thought that dereferencing The_Characters
-- would have caused Constraint_Error to occur.
exception
when Constraint_error =>
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters(1..0) caused Constraint_Error");
end;
begin
Null_Sequence.The_Characters(1..0) :=
Null_Characters;
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters succeeded");
exception
when Constraint_error =>
Put_Line("Null_Sequence.The_Characters(1..0) := "
&"Null_Characters caused Constraint_Error ?");
-- I thought, because Null_Characters(1..0) = Null_Characters,
-- that the assignment would have succeeded, as it did
-- in the previous block.
end;
end;
next reply other threads:[~2000-11-05 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-05 0:00 Vincent Marciante [this message]
2000-11-07 0:00 ` Simpler Question (was Assigning to dereferenced null access variable) Vincent Marciante
2000-11-07 0:00 ` Jean-Pierre Rosen
2000-11-07 0:00 ` Vincent Marciante
2000-11-08 4:20 ` Robert Dewar
2000-11-08 0:00 ` GNAT for OS/2 (was Re: Simpler Question (was Assigning ...)) Vincent Marciante
2000-11-10 1:52 ` tjerick
2000-11-08 0:00 ` Simpler Question (was Assigning to dereferenced null access variable) Vincent Marciante
2000-11-09 4:43 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox