* Please help! CONSTRAINT_ERROR: access check failed - This has me stumped!
@ 2006-12-22 12:49 tgwaltz
2006-12-22 13:12 ` Jean-Pierre Rosen
2006-12-22 13:30 ` Gautier
0 siblings, 2 replies; 4+ messages in thread
From: tgwaltz @ 2006-12-22 12:49 UTC (permalink / raw)
Hello all,
I have a small problem with a program that's supposed to represent a
doubly-linked list using pointers. I have most of the
functions/procedures programmed, at least as well as I can without
being able to run the program and test them! What happens is I get a
"access check failed" error whenever one of the functions is called
(i.e. "GetAtIndex, Remove, Contain, etc") I figure it must have
something to do with a value being set to null or something, but I've
stared at my laptop long enough and I can't figure it out myself. If I
can get this error fixed, then I can work through the rest of the
program and test my functions and so on.
The error occurs where I have a call to "anker.next" in the code.
I apologize that the comments in the program are in German - I am
studying abroad in Stuttgart this year. The function names and so on
are still English though - everything should be clear. "Anker" means
"anchor."
Thanks for you help!
TW
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure aufgabe1 is
procedure liste is
type zelle;
type ref_zelle is access zelle;
type zelle is record
v : integer;
prev : ref_zelle;
next : ref_zelle;
end record;
anker,a : ref_zelle;
max : natural := 10;
b : ref_zelle;
--Fuer das Leeren der Liste
procedure Empty is
begin
anker.next := null;
end;
--Fuer das Abfragen, ob die Liste leer ist
function IsEmpty return String is
begin
if anker.next = null then
return "true";
else
return "false";
end if;
end IsEmpty;
--Fuer das Abfragen der Laenge der Liste
function Length return Integer is
i : Integer := 0;
begin
while anker.next /= null loop
i := i + 1;
anker := anker.next;
end loop;
return i;
end Length;
--Fuer die Ausgabe der Liste
procedure Put is
begin
while anker /= null loop
put(anker.v);
anker := anker.next;
end loop;
a := anker;
end;
--Fuer das Abfragen des Elements an der gegebenen Position in der
Liste.
--Beachten Sie, dass die Position einen gueltigen Wert haben muss
function GetAtIndex(i : integer) return Integer is
begin
for q in 0..i loop
if anker.next /= null then
anker := anker.next;
else
--nicht gefunden/Liste nicht lang genug
return 58008;
end if;
end loop;
return anker.v;
end GetAtIndex;
--Fuer das Hinzufuegen eines Elements am Ende der Liste
procedure InsertAtEnd(val : Integer) is
begin
while anker.next /= null loop
anker := anker.next;
end loop;
anker.next := new zelle;
anker.next.v := val;
anker.next.prev := anker;
anker.next.next := null;
end InsertAtEnd;
--Fuer das Hinzufuegen eines Elements am Ende der Liste, falls
die Liste das Element nicht bereits enthaelt
procedure InsertAtEndIfNotExists(val : Integer) is
enthaelt : Boolean := False;
begin
while anker.next /= null loop
anker := anker.next;
if anker.v = val then
enthaelt := true;
end if;
end loop;
if not enthaelt then
anker.next := new zelle;
anker.next.v := val;
anker.next.prev := anker;
anker.next.next := null;
end if;
end InsertAtEndIfNotExists;
--Fuer das Hinzufuegen eines Elements an der
--Position einen gueltigen Wert haben muss
procedure InsertAtIndex(i : Integer; val : Integer) is
begin
b := new zelle;
for q in 1..i loop
if anker.next /= null then
anker := anker.next;
else
--nicht gefunden/Liste nicht lang genug
return;
end if;
end loop;
b.prev := anker;
b.next := anker.next;
b.v := val;
end InsertAtIndex;
--Fuer das Entfernen eines Elements, falls es in der Liste
vorhanden ist
procedure Remove(i : Integer) is
begin
for q in 0..i-1 loop
if anker.next /= null then
anker := anker.next;
else
--Liste nicht lang genug
return;
end if;
end loop;
if anker.next.next /= null then
anker.next := anker.next.next;
anker.next.next.prev := anker;
anker := anker.next.next;
end if;
end Remove;
--Fuer das Pruefen ob ein Element in der Liste enthalten ist
function Contain(val : Integer) return String is
begin
while anker.next /= null loop
anker := anker.next;
if anker.v = val then
return "true";
end if;
end loop;
return "false";
end Contain;
--Fuer das Abfragen, an welcher Position in der Liste ein Element
enthalten ist
function IndexOf(val : Integer) return Integer is
ind : Integer := 0;
begin
while anker.next /= null loop
if anker.v = val then
--nur das erste Ereignis wird ausgegeben
return ind;
end if;
anker := anker.next;
ind := ind + 1;
end loop;
return -1;
end IndexOf;
begin
anker := new zelle;
a := anker;
a.prev := null;
for i in 1..max-1 loop
a.v := i;
a.next := new zelle;
a.next.prev := a;
a := a.next;
end loop;
a.v := max;
a.next := null;
a := anker;
put("Normale Liste: "); --funktioniert
Put;
new_line;
put("Empty(): "); --funktioniert
--Empty;
--Put;
new_line;
put("IsEmpty(): "); --funktioniert
--put(IsEmpty);
--Put;
new_line;
put("Length(): ");
--put(Length);
new_line;
put("GetAtIndex(5): ");
--put(GetAtIndex(5));
new_line;
put("InsertAtEnd(11): ");
--InsertAtEnd(11);
Put;
new_line;
--passt
put("InsertAtEndIfNotExists(54): ");
--InsertAtEndIfNotExists(54);
Put;
new_line;
--passt nicht
put("InsertAtEndIfNotExists(2): ");
--InsertAtEndIfNotExists(2);
Put;
new_line;
put("InsertAtIndex(2,123): ");
--InsertAtIndex(2,123);
Put;
new_line;
put("Remove(2): ");
--Remove(2);
Put;
new_line;
put("Contain(8): ");
--Put(Contain(8));
Put;
new_line;
put("IndexOf(1): ");
Put(IndexOf(1));
Put;
new_line;
end liste;
begin
liste;
end aufgabe1;
Here's the output of the program:
[tgwaltz@tgwaltz Aufgabenblatt 9]$ ./aufgabe1
Normale Liste: 1 2 3 4 5
6 7 8 9 10
Empty():
IsEmpty():
Length():
GetAtIndex(5):
InsertAtEnd(11):
InsertAtEndIfNotExists(54):
InsertAtEndIfNotExists(2):
InsertAtIndex(2,123):
Remove(2):
Contain(8):
IndexOf(1):
raised CONSTRAINT_ERROR : aufgabe1.adb:157 access check failed
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-12-22 21:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-22 12:49 Please help! CONSTRAINT_ERROR: access check failed - This has me stumped! tgwaltz
2006-12-22 13:12 ` Jean-Pierre Rosen
2006-12-22 21:16 ` tgwaltz
2006-12-22 13:30 ` Gautier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox