comp.lang.ada
 help / color / mirror / Atom feed
* constraint-errors
@ 1996-10-06  0:00 Paul O Svelmoe
  1996-10-06  0:00 ` constraint-errors Michael Feldman
  1996-10-07  0:00 ` constraint-errors Tucker Taft
  0 siblings, 2 replies; 8+ messages in thread
From: Paul O Svelmoe @ 1996-10-06  0:00 UTC (permalink / raw)



Can someone please give me some general advice on what causes
constraint-errors?  For 2 years I have been plagued by them every time I
try to do any programming at all in Ada.  The only way I get by is by
continuing to try different things until something finally works, but I
never really understand what caused the crash in the first place.  Right
now I'm using a stack implemented as a linked list and a simple test 
'while not Is_Empty(sorted_stack)' is causing a constraing error.  I know
you can't diagnose that particular error just from that but I really want
to try and gain insight into this thing.  Can anyone point me in the right
direction?  Thanks so much.
Paul Svelmoe
zingbust@selway.umt.edu




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-06  0:00 constraint-errors Paul O Svelmoe
@ 1996-10-06  0:00 ` Michael Feldman
  1996-10-06  0:00   ` constraint-errors Robert Dewar
  1996-10-07  0:00 ` constraint-errors Tucker Taft
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Feldman @ 1996-10-06  0:00 UTC (permalink / raw)



In article <538vgm$2o1@server.umt.edu>,
Paul O Svelmoe <zingbust@selway.umt.edu> wrote:
>Can someone please give me some general advice on what causes
>constraint-errors?  For 2 years I have been plagued by them every time I
>try to do any programming at all in Ada.  The only way I get by is by
>continuing to try different things until something finally works, but I
>never really understand what caused the crash in the first place.  

Well, a traceback or debugger run will tell you just where in your
code the constraint error occurred.

Constraint_Error is raised when you violate a constraint. The most
common cases are:

- an attempt to store an out-of-range value into a variable
  (like a negative value into a Positive variable)

- an attempt to address an array element outside the array bounds
  (e.g., trying to retrieve A(15) when A is an array with bounds 1..10)

- an attempt to store into a variant record, referencing a field that
  doesn;t exist in the variant indicated by the discriminant (tag)

- an attempt to copy an array into another one with a different number
  of elements (e.g. a 15-character string into a 10-character one)

- an attempt to dereference a null access value (pointer) (e.g.
  looping through a linked list, trying to go one node beyond the
  last)

>Right
>now I'm using a stack implemented as a linked list and a simple test 
>'while not Is_Empty(sorted_stack)' is causing a constraing error.  I know
>you can't diagnose that particular error just from that but I really want
>to try and gain insight into this thing.  Can anyone point me in the right
>direction?  Thanks so much.

I can guess at a diagnosis: you are trying to look at the node pointed to
by a pointer that happens to be null. Draw a picture of your linked
list, find the line that caused the exception, and I'll bet you find
I was right in my guess. (I teach this stuff a lot, so I see lots
of cases like yours.)

BTW - not to hype books or anything, but Appendix H in that really
cool Feldman/Koffman text summarizes the exceptions in a way similar to
how I described it above.:-)

>Paul Svelmoe
>zingbust@selway.umt.edu

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman -  chair, SIGAda Education Working Group
Professor, Dept. of Electrical Engineering and Computer Science
The George Washington University -  Washington, DC 20052 USA
202-994-5919 (voice) - 202-994-0227 (fax) 
http://www.seas.gwu.edu/faculty/mfeldman
------------------------------------------------------------------------
       Pork is all that money the government gives the other guys.
------------------------------------------------------------------------
WWW: http://lglwww.epfl.ch/Ada/ or http://info.acm.org/sigada/education
------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-06  0:00 ` constraint-errors Michael Feldman
@ 1996-10-06  0:00   ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1996-10-06  0:00 UTC (permalink / raw)




">Can someone please give me some general advice on what causes
>constraint-errors?  For 2 years I have been plagued by them every time I
>try to do any programming at all in Ada.  The only way I get by is by
>continuing to try different things until something finally works, but I
>never really understand what caused the crash in the first place."


This kind of trial-and-error programming style is really worrisome, and
sometimes I am afraid far too much of it goes on in academic environments.
Trial and error is never a susbtitute for understanding. The real trouble
with programming by T&E is that it does not scale up at all.

But in academic environments, all too often people are working on small
programs and can get them to work by a mixture of T&E and asking for
help constantly and just taking the advice without understanding it (that's
something to think about the next time you feel like answering some
student doing Ada homework who asks for help on CLA!)

My favorite experience of this kind was from many years ago. A studen
who had supposedly complted several programming assignments came to me
with a listing and could not understand the error message:

   ***** else with no preceding if

I explained that indeed the program had an else with no if in sight

"Oh", said the student, "Should I add an if statement somewhere?"

:-)





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-06  0:00 constraint-errors Paul O Svelmoe
  1996-10-06  0:00 ` constraint-errors Michael Feldman
@ 1996-10-07  0:00 ` Tucker Taft
  1996-10-07  0:00   ` constraint-errors Michael F Brenner
  1 sibling, 1 reply; 8+ messages in thread
From: Tucker Taft @ 1996-10-07  0:00 UTC (permalink / raw)



Paul O Svelmoe (zingbust@selway.umt.edu) wrote:
: Can someone please give me some general advice on what causes
: constraint-errors?  For 2 years I have been plagued by them every time I
: try to do any programming at all in Ada.  The only way I get by is by
: continuing to try different things until something finally works, but I
: never really understand what caused the crash in the first place.  

If you look in Chapter 11 of the Ada reference manual, you will find
a list of causes of predefined exceptions (in the section entitled
"Suppressing Checks" -- admittedly a non-intuitive place to look for
this information).  Here are the most common causes:

   1) Attempting to dereference a null pointer
   2) Indexing beyond the end of an array
   3) Choosing a field of the "wrong" variant of a record 
   4) Going outside the bounds of an integer range.
   5) Forgetting to properly initialize a variable.
      
There are other possibilities, but these are probably the most common.

: ... Right
: now I'm using a stack implemented as a linked list and a simple test 
: 'while not Is_Empty(sorted_stack)' is causing a constraing error.  I know
: you can't diagnose that particular error just from that but I really want
: to try and gain insight into this thing.  Can anyone point me in the right
: direction?  Thanks so much.

If you are using linked lists, then by far the most common cause of
a constraint_error is dereferencing a null pointer.  In the above case,
I suspect that "sorted_stack" is a null pointer, and Is_Empty doesn't
check for that.

: Paul Svelmoe
: zingbust@selway.umt.edu

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-07  0:00 ` constraint-errors Tucker Taft
@ 1996-10-07  0:00   ` Michael F Brenner
  1996-10-07  0:00     ` constraint-errors Larry Kilgallen
  1996-10-10  0:00     ` constraint-errors Norman H. Cohen
  0 siblings, 2 replies; 8+ messages in thread
From: Michael F Brenner @ 1996-10-07  0:00 UTC (permalink / raw)



: Can someone please give me some general advice on what causes
: constraint-errors?
:: Here are the most common causes:
::
:: 1) Attempting to dereference a null pointer
:: 2) Indexing beyond the end of an array
:: 3) Choosing a field of the "wrong" variant of a record
:: 4) Going outside the bounds of an integer range.
:: 5) Forgetting to properly initialize a variable.

Constraint errors are the largest difference in the FEEL of programming
Ada versus other languages, and all programmers experience them, in part
because of compiler/runtime/system problems, and in part because the
programmers are being caught inserting bugs into their programs. Some
of us believe that programmer insertion is the main source of bugs, and
therefore, Ada's ability to catch them is a significant advantage. Some
additional common causes of constraint errors are the following:

6) running out of memory at run-time   
7) not explicitly sliding an array (occurs much less in Ada 95)
8) dereferencing a pointer that is not memory mapped to real memory
9) dereferencing a pointer to non-existent virtual memory
10) taking the square root of -1
11) dividing by zero
12) taking the arctangent of (0, 0)
13) taking the logarithm of a negative real number
14) giving an invalid code to the floating point unit
15) moving a small array or string into a big array or string
16) moving a big array or string into a small array or string
17) using a subtype or type that has no element past the beginning or end
18) proceeding in a loop, going one item past the end of the subtype
19) invoking a run-time routine that fails
20) invoking an operating system call that fails
21) executing the Ada statement: RAISE CONSTRAINT_ERROR

and many others





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-07  0:00   ` constraint-errors Michael F Brenner
@ 1996-10-07  0:00     ` Larry Kilgallen
  1996-10-10  0:00     ` constraint-errors Norman H. Cohen
  1 sibling, 0 replies; 8+ messages in thread
From: Larry Kilgallen @ 1996-10-07  0:00 UTC (permalink / raw)



In article <53bidr$en6@linus.mitre.org>, mfb@mbunix.mitre.org (Michael F Brenner) writes:

> Constraint errors are the largest difference in the FEEL of programming
> Ada versus other languages, and all programmers experience them, in part

In my experience, Ada constraint error have much the same feel as
similar errors encountered after compiling with a good Pascal compiler.

> Ada versus other languages, and all programmers experience them, in part
> because of compiler/runtime/system problems, and in part because the
> programmers are being caught inserting bugs into their programs. Some
> of us believe that programmer insertion is the main source of bugs, and
> therefore, Ada's ability to catch them is a significant advantage. Some

And some of us believe that even compiler/runtime/system problems
are better handled by being detected rather than ignored :-).

Larry Kilgallen




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-07  0:00   ` constraint-errors Michael F Brenner
  1996-10-07  0:00     ` constraint-errors Larry Kilgallen
@ 1996-10-10  0:00     ` Norman H. Cohen
  1996-10-11  0:00       ` constraint-errors Robert Dewar
  1 sibling, 1 reply; 8+ messages in thread
From: Norman H. Cohen @ 1996-10-10  0:00 UTC (permalink / raw)



Michael F Brenner wrote:
> 
> : Can someone please give me some general advice on what causes
> : constraint-errors?
> :: Here are the most common causes:
> ::
> :: 1) Attempting to dereference a null pointer
...
> :: 5) Forgetting to properly initialize a variable.
> 
...
>                                                                   Some
> additional common causes of constraint errors are the following:
> 
> 6) running out of memory at run-time
...
> 21) executing the Ada statement: RAISE CONSTRAINT_ERROR
> 
> and many others

Having read this, I obviously had no choice but to dig up the following
slide from a talk I gave at the winter 1987 SIGAda meeting in Hollywood,
Florida:

 |        THERE MUST BE FIFTY WAYS
 |       TO RAISE CONSTRAINT_ERROR
 |
 | o Assignment statements that break, Jake
 | o Initial values that don't fit, Kit
 | o An out-of-range index, Rex
 | o A variant that's gone, John
 | o Bad actuals in, Lynn
 | o Bad formals copied back, Jack
 | o Bad function return, Fern
 | o An exponent minus, Linus
 | o Different-length arrays for "or", Lenore
 | o Catenation too large, Marge
 | o Dereferencing nil, Jill
 | o A wrong value for 'Val, Sal
 | o A bad aggregate part, Bart
 | o A foiled attempt to convert, Bert
 | o Making "digits" too few, Lou
 | o Making "delta" too much, Dutch
 | o A range constraint that's bad, Chad
 | o A wrong value for "new", Stu
 | o ... and many more, too!

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: constraint-errors
  1996-10-10  0:00     ` constraint-errors Norman H. Cohen
@ 1996-10-11  0:00       ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1996-10-11  0:00 UTC (permalink / raw)



"> additional common causes of constraint errors are the following:
>
> 6) running out of memory at run-time"



surely not, Storage_Error should be raised in this situation.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1996-10-11  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-06  0:00 constraint-errors Paul O Svelmoe
1996-10-06  0:00 ` constraint-errors Michael Feldman
1996-10-06  0:00   ` constraint-errors Robert Dewar
1996-10-07  0:00 ` constraint-errors Tucker Taft
1996-10-07  0:00   ` constraint-errors Michael F Brenner
1996-10-07  0:00     ` constraint-errors Larry Kilgallen
1996-10-10  0:00     ` constraint-errors Norman H. Cohen
1996-10-11  0:00       ` constraint-errors Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox