From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,932267eb02cfdff6 X-Google-Attributes: gid103376,public From: kevq@banana.demon.co.uk (Kevin F. Quinn) Subject: Re: raised Constraint_Error? Date: 1995/04/04 Message-ID: <19950404.003251.35@banana.demon.co.uk>#1/1 X-Deja-AN: 100815598 sender: news@demon.co.uk (Usenet Administration) x-nntp-posting-host: banana.demon.co.uk references: organization: The Banana Arc reply-to: kevq@banana.demon.co.uk newsgroups: comp.lang.ada Date: 1995-04-04T00:00:00+00:00 List-Id: In article , winchest@csee.usf.edu (Jeff Winchester) wrote: > Could anyone tell me why the following code would cause a constraint > error? I've been pulling out hairs for a couple of days now and am > obviously overlooking something simple. Thanks. Indeed you are - dereferencing null pointers you naughty boy :) > current := head; > while current /= null loop OK, assume here that current.next = NULL (which it will be, eventually, assuming the list isn't looped)... > if (current.name (current.nl)) = (sname (snl)) then > current := current.next; So now current=NULL > if (current.class (current.cl)) = (sclass (scl)) then Crash and burn. > current := current.next; > if (current.number = snumber) then > current := current.next; > pay := current.cost; Ditto here, of course (if current.next.next on entry to loop is NULL). > [...deletia...] > text_io.put ("Thank you. Your change is $"); > flt_io.put (item => pcost, aft => 2, exp => 0); > else current := current.next; \ > end if; | Phew! Scratch > else current := current.next; | this lot for a > end if; \ start! Put the > else current := current.next; / c := c.next > end if; | outside all the ifs. > else current := current.next; | > end if; / > exit when current = null; <--- This is redundant, BTW > end loop; > end price; I'm not doing both for you :) A tip for the above, I would suggest flattening stuff a bit. Inside the loop, it's best only to consider current.*, and not any deeper than that. Only traverse the list at the end of the loop, i.e. immediately before the check "current /= NULL": while current /= NULL loop [Lots of wibble about current. here - don't change current] current := current.next; end loop; BTW Why not ask your course lecturer? That's what they're for... -- Kevin F. Quinn * "No-one ever made any money out of good kevq@banana.demon.co.uk * looks and charm." kevq@cix.compulink.co.uk * "You obviously haven't met Lady Hamilton..." Compu$erve: 100025,1525 * Blackadder III